Friday, November 21, 2008

Adding Photos to iPhone Library

Here's a tip I picked up from the iPhoneDevSDK forums courtesy of member hikinks.

The iPhone simulator comes with some sample images installed so that you can use and test the Image Picker and other functionality. The only problem is, if you clear the cache, or delete the ~/Library/Application Support/iPhone Simulator folder, you lose them.

You can put any photos you want in the library, however, to get them to show up, you need to put them in the right place and give them the correct names. Place your images in
~/Library/Application Support/iPhone Simulator/User/Media/DCIM/100APPLE

creating any folders that do not exist.

Now, rename the image files you want in your simulator's photo library using the following naming convention:

IMG_0000.JPG
IMG_0001.JPG
IMG_0002.JPG

Remember - unlike the Mac, the iPhone's file system is case sensitive, so make sure you use uppercase letters.

That will put them in the photo album. You do not see thumbnails though. To get thumbnails, you have to manually make re-sized copies of each image that are resized to 96x96 pixels. The thumbnail for a particular image should have the same name as the image it is a thumbnail for, but instead of a .JPG extension, it should have a .THM extension.


The Of Code and Men blog has a bash script that will functions for copying the files onto the simulator.

Edit: I've been told that there's an easier way - that you can simply drag an image onto the Simulator window when it's running and that will open the image in Mobile Safari and then let you add the image to the Simulator's Photo Library. I've found that to be half true - I can get the image from my computer to open in Mobile Safari in the Simulator, but the path from there to the Photo Library is not obvious to me if it exists.

No comments:

Post a Comment