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.




8 comments:

Scott Squires said...

Hold down the mouse button in the simulator. A sheet will appear asking if you want to save the image. Click Ok. (Just like saving images from the web on the iPhone.)

h said...

The tap-and-hold trick works, but it's not convenient for lots of images.

The reason I made the batch script is that I have to work with different pictures on my projects and sometimes I need a 1x1 or a 2048x2048 picture. So I took a couple images I use as wallpaper, redimensionned them using sips, and added them automatically to the simulator.

Total time: less than 20 minutes for a hundred pics. a couple minutes more for making the post ;-)

Have fun.
h/poltras

catfacts3192 said...

The mac is case sensitive too. Image.jpg is different from image.jpg in Mac just like iPhone. They are the same core OS remember.

h said...

@catfacts3192 By default, the Mac is on a case preserving, case insensitive HFS by default (and the system volume should be kept that way, otherwise it's unstable). iPhone is case sensitive by default. Simulator is case insensitive.

Gregorio Gallery said...

Thanks for the lead. There is a typo in your nameing "hikinks", it is actually "hijinks".

Mark said...

i3 Simple Steps

1) Drag & Drop onto Simulator
- this will open a browser with your image
2) Click & Hold
- This will open options tab
3) save image

you can do this for any web image
from simulator web browser:
click & hold image
Save image that's it
it's actually 2 steps
check out video at http://www.youtube.com/watch?v=1NqHnYGNAp8

Mark said...
This comment has been removed by the author.
h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels