在模态视图中,我有一个 imageView,我在其中设置来自画廊或相机的图像。几次它完美地工作,但随着选择数量的增加应用程序崩溃。我正在使用这段代码
- (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];
}
我猜 CFDataRef 导致崩溃,可能是它没有以正确的方式释放,因为我增加了百万像素(12 到 16MP)应用程序的崩溃频率增加。有什么想法吗?