tags:

views:

54

answers:

1

Hello All,

I am working on one component where I need to scale and rotate image. following is flow of the component

Select the image from photo library -> show that image in UIImageView -> do the scaling -> save this image in document.

This works fine with image having low resolution.

but once I select the image with high resolution I first get Memory Warning level 1. but I cann't release that image, as I need to proceed further with same image.

I come to know image is unpacked by ( width * height * 4 ) so if I select image of 1800 * 1200 memory consumed is 8.6 MB [ Also checked with instrument ] .

Can any one help me to come over this issue? This creates 2 queuestion

  1. can we use images with high resolution ?
  2. what about 2 UIImageview with two high resolution images?

Thanks,

Sagar

A: 

You could change your order of operations a bit.

Select the image from the photo library -> scale the image -> save the scaled image to the Documents directory -> show the scaled image in the UIImageView.

Scaling and saving the image takes time, so your user will have a bit of a wait before they see the image in your UIImageView. Displaying an activity indicator with a cancel option is a good idea.

I've used this technique with pretty large images and it worked on older devices without incurring memory warnings.

Robot K
Also, be aware of autorelease pools. If not careful, objects can remain live longer than expected.
rpetrich
Thanks Robot for quick reply , but the protocol is user will 1st pick the image and if need then he will use scale option to scale it to fit full screen. so struggling with this.
Sagar Mane
It's not clear to me what you mean by "scale it to fit full screen". Why not use the image picker's ability to select a portion of the image? Alternatively, if the image is already much bigger than "full screen", save off a version that's scaled down to the screen's resolution and use that. It will still use much less memory than the original.
Robot K
rpetrich is right. Be very leery of autoreleased objects. It's smart to avoid them if possible, or set up your own autorelease pools if not.
Robot K
You are right Robot. **It's not clear to me what you mean by "scale it to fit full screen"** - This is incase if I select the lower resolution image from library and wanna make fit to screen. @rpetrich : yes need to implement that.
Sagar Mane
I'm not saying to be leery of them, I'm saying to be aware. High-level API calls will often create autoreleased objects internally; even if you avoid them in your own code, they can be created without your knowledge.
rpetrich
From this seems like , we cann't hold images with high resoultion ? we have to scale it down.
Sagar Mane
Apple does this in the Photos app. They take great pains to avoid loading the full sized image into memory by using smaller versions when they can get away with it.
Robot K
Yes Robot ( PhotoScroller ) is the sample regarding same. where large images are handle using tiles.
Sagar Mane