views:

698

answers:

2

I have an iPhone application that downloads images from the internet and saves them for display later.

The user can select the images to view from a UITableView, the table view has custom cells which display thumbnails of the original images in varying sizes.

When the large image is first downloaded it is scaled to thumbnail size and the thumbnail is saved using UIImagePNGRepresentation.

What I would like to do is save the thumbnail in the optimized iPhone PNG format. How can I do that? does it happen magically just by loading the original large image into memory and saving it? Do I have to do any further processing on the thumbnail before saving?

+1  A: 

Chances are the UIImagePNGRepresentation does not create the images, as they are non-comformant PNGs, and can't be read by anything else. If they API generated PNGs that could not be read I think it would document that, and anyone who uploads PNGs from the phone would notice that they did not work.

The optimization is useful, but most of the optimized PNGs are part of the UI where the optimization is done as part of the build process. Chances are the cost of performing the optimization will offset any gains you get from it.

Louis Gerbarg
Not my images, they come from the web so are not optimized for the device. If I COULD save the images in an optimized format then the cost you mention would be one-time and at a time the user is already in 'waiting mode'.
oldbeamer
Sure, but two points. First off, it would be a lot of work. Second optimized PNGs are more efficient than normal PNGs, which are necessary for lossless content (like the UI). A lot of web content is lossy stuff (JPG), and the increase in file size costs more than the decompression. Remember the device flash is slow, reading a 60k file takes longer than a 12k one. If your original source something lossy just uses JPGs.
Louis Gerbarg
A: 

So it turns out that the RGB565 colorspace used in the optimized format is simply not available in a CGGraphicsContext, which is the rendering class used by all the UIwhatever components.

So if I DID write some code to change the color space of the image before saving it, I couldn't get the texture back into a UI class. The only way to use it is to load it directly into the OpenGL innards and use OpenGL in my app.

oldbeamer