views:

338

answers:

3

In the iPhone sample code "PhotoScroller" from WWDC 2010, they show how to do a pretty good mimmic of the Photos app with scrolling, zooming, and paging of images. They also tile the images to show how to display high resolution images and maintain good performance.

Tiling is implemented in the sample code by grabbing pre scaled and cut images for different resolutions and placing them in the grid which makes up the entire image.

My question is: is there a way to tile images without having to manually go through all your photos and create "tiles"? How is it the Photos app is able to display large images on the fly?

Thanks for the help!

+1  A: 

I've found this which may be of help: http://www.mikelin.ca/blog/2010/06/iphone-splitting-image-into-tiles-for-faster-loading-with-imagemagick/

You just run it in the Terminal as a shell script on your Mac.

iWasRobbed
That's pretty cool and could save a lot of time. But, what I was looking for is a way to do it within the phone. For example, the Photos app is able to quickly pan/zoom even large images. My guess is that it tiles the images automatically. But, I may be wrong.
Jonah
+2  A: 

Sorry Jonah, but I think that you cannot do what you want to.

I have been implementing a comic app using the same example as a reference and had the same doubt. Finally, I realized that, even if you could load the image and cut it into tiles the first time that you use it, you shouldn't. There are two reasons for that:

  1. You do the tiling to save time and be more responsive. Loading and tiling takes time for a large image.
  2. Previous reason is particularly important the first time the user runs the app.

If these two reasons make no sense to you, and you still want to do it, I would use Quartz to create the tiles. CGImage function CGImageCreateWithImageInRect would be my starting point.

Jorge Ortiz
Definitely agree about doing the tiling yourself in the program... you'd have to load the image into memory which defeats the purpose of tiling to begin with (to save memory). Might be able to upload images to a server and have it pre-cut the images and then re-download them.
iWasRobbed
That makes sense. But, my question is then: How on earth does the photos app do it? Someone can email you a 10mb photo and it's works perfectly in the photos app. So if not tiling within the app, how'd they do it?
Jonah
As I mentioned, it can be done with Quartz and the impact isn't so big when the user assumes that it is importing a photo, I think.As for iTunes, you can read a message that says something like "Optimizing photos for the iPod", which I guess is for the tiling
Jorge Ortiz
A: 

Many image formats support region-based decoding. Instead of loading the whole image into memory, decompressing the whole thing, and discarding all but the region of interest (ROI), you can load and decode only the ROI, on-demand. For the most part, this eliminates the need to pre-generate and save image tiles. I've never worked with ImageMagick but I'd be amazed if it couldn't do it. (I have done it using the Java Advanced Imaging (JAI) API, which isn't going to help you on the iPhone...)

I've played with the PhotoScroller example and the way it works with pre-generated tiles is only to demonstrate the idea behind CATiledLayer, and make a working-self contained project. It's straightforward to replace the image tile loading strategy - just rewrite the TilingView tileForScale:row:col: method to return a UIImage tile from some other source, be it Quartz or ImageMagick or whatever.

alexantd