views:

27

answers:

3

I'm developing a simple image processing app and I've encountered an issue on my test unit (iPhone 3G) that generally any image over 1024x1024 pixels will cause the app to crash when saving.

The process my app follows:

  1. User selects an image via UIImagePicker

  2. A working copy of the selected image is created and resized to the view bounds (e.g. 320x480) for performance.

  3. User does their image manipulations on the working copy and presses save

  4. The same manipulations are done on the original full-res image, then saved to the photo album.

  5. If the image is is the region of 1024x1024 all is fine, if too large the app crashes without any memory warning.

After searching through stackoverflow it seems that there this a recommendation from Apple to not exceed 1024x1024, however I've found that the PhotoShop Express app on the same iPhone 3G is able to save images at their original high resolution (e.g. 1534x2034).

Could someone give me some ideas as to how to save high-res images to the photo album like PhotoShop Express is able to?

Thanks.

+1  A: 

Even though there is no memory warning, I'm assuming this is a memory issue. We'd need more information about your crash to know for sure. How are you saving it? Are you using ALAssetsLibrary or UIImageWriteToSavedPhotosAlbum? Note that the latter has methods that work with CGImageRef or NSData. Its worth trying all applicable methods to compare.

Peter DeWeese
+1  A: 

I'm using UIImageWriteToSavedPhotosAlbum for the save, but I've found that the app is crashing before it gets to the save step.

  1. First I UIGraphicsBeginImageContext(size) to the full resolution (e.g. 1536x2048)
  2. Then I attempt to use drawInRect to the image context with a fullres UIImage pulled from [imginfo objectForKey:@"UIImagePickerControllerOriginalImage"]
  3. I apply the user's post processing steps
  4. Obtain the final image by UIGraphicsGetImageFromCurrentImageContext() then save using UIImageWriteToSavedPhotosAlbum().

When stepping through the program I find that it crashes at the drawInRect step (Program received signal "0"). Any ideas what is causing the crash? The crash is not occurring with lower-res images.

MrDB
+1  A: 

Thought I'd share how I moved forward with this issue...

  1. Load the image from photo library. [imginfo objectForKey:@"UIImagePickerControllerOriginalImage"];
  2. Resize a "working copy" to a size that fits in the view bounds.
  3. At the time of saving, I have a method which determines which model iOS device it's running on, and returns that max resolution for one dimension. For iPhone 3G I used 1600px.
  4. The original image is loaded again (objectForKey:@"UIImagePickerControllerOriginalImage"];) then resized to fit within the bounds of 1600px (in this case) whilst maintaining the aspect ratio.

Not ideal, but at least this prevents the crash, and allows individuals with newer hardware (e.g. 3Gs or 4) to save at higher resolutions.

MrDB