Saving hi-res images to photo album
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:
User selects an image via UIImagePicker
A working copy of the selected image is created and resized to the view bounds (e.g. 320x480) for performance.
User does their image manipulations on the working copy and presses save
The same manipulations are done on the original full-res image, then saved to the photo album.
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.
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.
Thought I'd share how I moved forward with this issue...
- Load the image from photo library. [imginfo objectForKey:@"UIImagePickerControllerOriginalImage"];
- Resize a "working copy" to a size that fits in the view bounds.
- 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.
- 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.
精彩评论