-1

In didFinishPickingMediaWithInfo I'm normalizing the image but I`m getting Received Memory warning and crash in some devices when I take a picture . Why?

- (void) imagePickerController:(UIImagePickerController *)picker 

didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        // Save image

        image = [self normalizedImage:image];

      //  UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
        self.image = image;
        [self salvarImagem:image];
    }

- (UIImage *)normalizedImage:(UIImage*)imgtratar {
    if (imgtratar.imageOrientation == UIImageOrientationUp) return imgtratar; 

    UIGraphicsBeginImageContextWithOptions(imgtratar.size, NO, imgtratar.scale);
    [imgtratar drawInRect:(CGRect){0, 0, imgtratar.size}];
    UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return normalizedImage;
}

EDIT: I have already searched and the solutions don't work for me... I debugged and the error is in

  [imgtratar drawInRect:(CGRect){0, 0, imgtratar.size}];
Ladessa
  • 985
  • 4
  • 24
  • 50

2 Answers2

0

Maybe because you forgot the line

[self dismissModalViewControllerAnimated:YES];

right after UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

And/Or compress and convert the image to JPEG format.Check UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality).

N.B. Please search first for existing solution. you will find some here, here and lots in here

Community
  • 1
  • 1
x4h1d
  • 6,042
  • 1
  • 31
  • 46
0

I solved my problem resizing the image...the problem was because the image was too big

- (UIImage *)normalizedImage:(UIImage*)imgtratar {
    if (imgtratar.imageOrientation == UIImageOrientationUp) return imgtratar; 

    UIGraphicsBeginImageContext(CGSizeMake(117, 175));
    [imgtratar drawInRect:(CGRect){0, 0, 117, 175}];
    UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return normalizedImage;
}
Ladessa
  • 985
  • 4
  • 24
  • 50