我的应用程序在所有设备和 ios 版本上都可以正常工作,但是对于 ipad mini,在 iOS7 上,当我分配:初始化 UIImagePickerController 并显示时。获取图像后,应用程序突然发出低内存警告并崩溃。这是我捕获图像的代码。
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePickerController;
if ([UIUtilityClass isCurrentVersionIsIOS7OrGreater]) {
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setDelegate:self];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage,nil];
imagePickerController.allowsEditing=NO;
CGFloat scaleFactor=1.3f;
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationLandscapeLeft:
imagePickerController.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * 90 / 180.0), scaleFactor, scaleFactor);
break;
case UIInterfaceOrientationLandscapeRight:
imagePickerController.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);
break;
case UIInterfaceOrientationPortraitUpsideDown:
imagePickerController.cameraViewTransform = CGAffineTransformMakeRotation(M_PI * 180 / 180.0);
break;
default:
break;
}
}
else
{
imagePickerController = [[NonRotatingUIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage,nil];
imagePickerController.allowsEditing = YES;
}
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate=self;
[popoverController presentPopoverFromRect:CGRectMake(626,142,120,135) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[imagePickerController release];
newMedia = YES;
}
之后,我使用以下代码捕获图像。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[popoverController dismissPopoverAnimated:true];
[popoverController.delegate popoverControllerDidDismissPopover:popoverController];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
int orientation=image.imageOrientation;
image=[image imageToFitSize:PIC_SIZE method:MGImageResizeCrop];
switch (orientation) {
case UIImageOrientationUp:
// do nothing
break;
case UIImageOrientationDown:
image=[image imageRotatedByDegrees:180.0];
break;
case UIImageOrientationLeft:
image=[image imageRotatedByDegrees:90.0];
image=[image imageRotatedByDegrees:180];
break;
//2
case UIImageOrientationRight:
image=[image imageRotatedByDegrees:-90.0];
image=[image imageRotatedByDegrees:180];
break;
default:
break;
}
}