oldbeamer
oldbeamer

Reputation: 1285

Converting a normal PNG to iPhone Optimized format

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?

Upvotes: 1

Views: 1987

Answers (3)

Kornel
Kornel

Reputation: 100200

Don't worry about the "optimized PNG" format, as it isn't making any significant difference.

It does not affect rendering speed at all, and loading speed is dictated by file size more than file format.

So simply save it in a format that will give you smallest files. If you're not using transparency, then it might be JPEG.

If you need transparency, and can spend more CPU time when saving images, then include pngquant in your program (it's under BSD-like license) and shrink those PNGs to 8-bit palette.

Upvotes: 0

oldbeamer
oldbeamer

Reputation: 1285

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.

Upvotes: 0

Louis Gerbarg
Louis Gerbarg

Reputation: 43462

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.

Upvotes: 2

Related Questions