I have an app using the camera to take pictures. As soon as the picture is taken, I reduce the size of the image coming from the camera.
Running the method for reducing the size of the image, makes the memory usage peaks from 21 MB to 61 MB, sometimes near 69MB!
I have added @autoreleasepool to every method involved in this process. Things improved a little bit, but not as much as I expected. I don't expect the memory usage jump 3 times when reducing an image, specially because the new image being produced is smaller.
These are the methods I have tried:
- (UIImage*)reduceImage:(UIImage *)image toSize:(CGSize)size {
@autoreleasepool {
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, size.width, size.height), image.CGImage);
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
}
and also
- (UIImage *)reduceImage:(UIImage *)image toSize:(CGSize)size {
@autoreleasepool {
UIGraphicsBeginImageContext(size);
[image drawInRect:rect];
UIImage * result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
}
no difference at all between these two.
NOTE: the original image is 3264x2448 pixels x 4 bytes/pixel = 32MB and the final image is 1136x640, that is 2.9MB... sum both numbers and you get 35MB, not 70!
Is there a way to reduce the size of the image without making the memory usage peak to stratosphere? thanks.
BTW and out of curiosity: is there a way to reduce an image dimension without using Quartz?