Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jpg or png for UIImage -- which is more efficient?

I am grabbing an image from the camera roll and then using it for a while as well as save it to disk as a PNG on the iPhone. I am getting the odd crash, presumably due to out of memory.

Does it make a difference if I save it as PNG or JPG (assuming I choose note to degrade the quality in the JPG case)? Specifically:

  • is more memory then used by the UIImage after I reload it off of disk if I saved it as a PNG?
  • is it possible the act of saving as PNG uses up more memory transiently during the saving process?

I had been assuming the UIImage was a format neutral representation and it shouldn't matter, but I thought I should verify.

like image 920
Stephen Petschulat Avatar asked Apr 29 '09 04:04

Stephen Petschulat


2 Answers


I am getting the odd crash, presumably due to out of memory


Then STOP WHAT YOU ARE DOING RIGHT NOW and first figure out if that's actually the cause of the crash. Otherwise there's a very good chance that you're chasing the wrong problem here, fixing a memory problem that doesn't exist while ignoring the real cause of the crash. If you want to fix a crash, start by figuring out what caused the crash. Following up on what's "presumably" the problem is a recipe for wasted time and effort.

like image 140
Tom Harrington Avatar answered Sep 25 '22 07:09

Tom Harrington


I have an application on the store that needs to save intermediate versions of an image as it's being edited. In the original version, I used PNG format for saving, to avoid quality loss from loading and saving JPEG multiple times.

Sometime around the 2.2 software release, Apple introduced a change into the PNG writing code, such that it takes many times longer to save PNG data from some images. I ended up having to change to saving in JPEG format, because my application was timing out when trying to save images on exit.

Also, you'll run into issues because saving in PNG format doesn't preserve the "orientation" information in the UIImage, so a picture taken in Portrait orientation with the built-in camera will appear rotated after you save and reload it.

like image 38
Mark Bessey Avatar answered Sep 26 '22 07:09

Mark Bessey