ImagePickerController crash

227 Views Asked by At

In a modal view, i have an imageView in which i set the image from gallery or camera. few times it works perfectly, but as number of selection increases application crashes.I'm using this code

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        UIImage *selectedImage1 = [[info objectForKey:UIImagePickerControllerOriginalImage] fixOrientation];
        NSLog(@"size is %@",NSStringFromCGSize(selectedImage1.size));
        CGImageRef imageRef=[selectedImage1 CGImage];
        float width=CGImageGetWidth(imageRef);
        float height=CGImageGetHeight(imageRef);
        NSLog(@"length is %f",width*height);
        if (width*height<=12012000.0) {//12MP
            CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
            float length = CFDataGetLength(data);
            CFRelease(data);
            NSLog(@"data==%f ",length);

            if ((length/10)>10485760.0) {//10 MB
                NSLog(@"data length less than 10 mb==%f ",length);
                [imagePickerPopover dismissPopoverAnimated:YES];

                return;
            }
        }else{
            [imagePickerPopover dismissPopoverAnimated:YES];
            return;
        }

self.selectedImage=selectedImage1;
            [imagePickerPopover dismissPopoverAnimated:YES];

}

i guess CFDataRef is causing crash, may be its not released the right way, as i increase the Megapixels(12 to 16MP) application's crashing frequency increases.Any ideas?

1

There are 1 best solutions below

1
iPatel On

Use ELCImagePickerController,

It is Best for you, By using ELCImagePickerController you can select multiple image in gallery and save it in you image view with swipe facility

You can get source code from Here.

This might helpful for you.

Thanks.