views:

712

answers:

2

I'm working on an iPhone App that uses the camera to take pictures, then I'm saving them to the Applications Documents directory. I'm using the following code to convert the UIImage to NSData,

NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];

Then I write the NSData using

[imageData writeToFile:path atomically:NO]

It all works. The problem is that UIImagePNGRepresentation() is really slow. It takes 8-9 secs on my 3G to convert the image to NSData. This seems wrong to me. Does anyone have any experience with this? Is this just slow function or am I doing something terribly wrong?

Thanks

A: 

In my experience it's quite slow, even on a 3GS.

bpapa
+5  A: 

Are you sure you want to save pictures captured with the camera as PNG?

JPEG is a more appropriate format for photographs. Additionally, its likely much faster!

Will
JPeg is much faster indeed, (never used PNG, but Jpeg never takes 9 seconds, takes like 1)
Daniel
should have included this nugget of info as well in my answer. It's not blazing fast but it is much faster than the PNG method.
bpapa
Much faster indeed. The PNG conversion took 8.941264 secs and the JPG at 0.9 takes 3.222942.Problem solved in less than 5 mins, I love this site.
TheGeoff