user2415476
user2415476

Reputation: 221

UIImage from UIImagePickerController too large

I get an image from the Iphone 5 camera with

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:   (NSDictionary *)info {
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    ...
    }

According to the Debug Navigator the image size must be about 30MB. After the method is finished (when nothing is done in the method), these 30MB become free again. But, when I want to save the image with this line of code in the method above:

self.myImage = [UIImage imageWithData:UIImageJPEGRepresentation(image, 0.8)];

The 30MB stay in memory. I understand that there must be some memory used for the image, but not 30MB. I thought I decreased the original image size with UIImageJPEGRepresentation()?

Is there another way to decrease the file size of an image, without changing height and width?

Upvotes: 0

Views: 1370

Answers (1)

Jack
Jack

Reputation: 16865

[UIImage imageWithData:UIImageJPEGRepresentation(image, 0.8)]

This line of code actually does nothing to the memory footprint of the image. It simply causes it to be lower quality due to JPEG representation.

The only way you can lower the memory footprint, assuming you need to display the image, is to crop/scale it to a smaller size.

If you do not need to display the image, you can store the image in JPEG format by storing the return NSData returned by UIImageJPEGRepresentation(image, 0.8)]

Upvotes: 1

Related Questions