views:

423

answers:

2

Hello,

I have two files in the Documents directory of the same image taken with the camera. One was saved using UIImagePNGRepresentation and the the other one using UIImageJPEGRepresentation. In other word, one is a png and the other is a jpg.

Now, using the the instrument with a real device. if I load the png (initWithContentOfFile:), the 'Real memory' goes from 2.34 MB to 2.43 MB. But if I load the jpeg instead, the memory goes from 2.34 MB to over 23 MB!!! I had similar results loading any png versus jpeg.

Can somebody can help me understand why?

A: 

It's probably able to map the memory used for the PNG file directly to storage, whereas it has no ability to do this with a JPG which must be decoded.

If you think about it, for a 1600x1200 image from the iPhone camera, 23 MB is very realistic while .09 MB is not enough space to hold the data for an image.

Kendall Helmstetter Gelner
PNG is a format that do lossless compression. Thus, it must also be decoded.
Yoshi
But you can do the decompression more or less "in place". With JPG you pretty much have to load the whole thing into memory and computationally it's not really practical to do that on the fly.
Kendall Helmstetter Gelner
A: 

Apple has a special no-standard format for png files where the color bytes are in the same order as the color stripes on the iPhone display. Png images Resources are re-written when copied to the app bundle by Xcode. I suspect that png representations are special cased when used as images on the iPhone.

zaph
The PNGRepresentation method does not use that compression technique though, or nothing else would be able to read the files!
Kendall Helmstetter Gelner