在我的应用程序中,我按一下按钮就会连续拍摄五张照片。但是,当我在这张照片中按下设备中的主页按钮时,通常应用程序进入其后台阶段,但是当我尝试重新启动时,应用程序崩溃了。你能为这个问题建议任何解决方案吗?
提前致谢
答案 0 :(得分:2)
嗨,请参考这三种方法,这可能会解决您的内存泄漏问题,实际上崩溃是由于内存泄漏,因为有时当我们拍摄更多高分辨率的照片并且我们正在使用它是我们的应用程序然后iphone无法处理太多更多的记忆。
还有一件事我需要说对不起,因为我不知道如何格式化代码。
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; [选择器发布];
[popover dismissPopoverAnimated:YES]; [popover release];
UIImage * capturedImage = [info objectForKey:@“UIImagePickerControllerOriginalImage”]; [self performSelector:@selector(waitUntillImageCaptured :) withObject:capturedImage afterDelay:0.2]; }
- (void)waitUntillImageCaptured:(UIImage *)originalImage
{
UIImage * tempimg;
tempimg = [self scaleAndRotateImage:originalImage];
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * imagePath = [[appDelegate applicationDocumentDirectoryString] stringByAppendingPathComponent:@“ClientTempthumb.png”];
// UIImageView * tempView = [[UIImageView alloc] initWithImage:tempimg]; NSData * data = [NSData dataWithData:UIImagePNGRepresentation(tempimg)];
if(data!= nil) { [data writeToFile:imagePath atomically:YES]; } 其他 { [[NSFileManager defaultManager] removeItemAtPath:imagePath error:NULL]; }
[btnPhoto setImage:tempimg forState:UIControlStateNormal]; [池发布]; // [appDelegate hideLoadingView]; }
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef); CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform = CGAffineTransformIdentity; CGRect bounds = CGRectMake(0,0,width,height); if(width> kMaxResolution || height> kMaxResolution){ CGFloat比率=宽度/高度;
if (ratio > 1)
{
bounds.size.width = kMaxResolution;
bounds.size.height = roundf(bounds.size.width / ratio);
}
else
{
bounds.size.height = kMaxResolution;
bounds.size.width = roundf(bounds.size.height * ratio);
}
}
CGFloat scaleRatio = bounds.size.width / width; CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef),CGImageGetHeight(imgRef)); CGFloat boundHeight; UIImageOrientation orient = image.imageOrientation;
开关(定向) {
case UIImageOrientationUp: //EXIF = 1
// landscape right
transform = CGAffineTransformIdentity;
break;
case UIImageOrientationUpMirrored: //EXIF = 2
transform = CGAffineTransformMakeTranslation(imageSize.width, 0.0);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
break;
case UIImageOrientationDown: //EXIF = 3
// landscape left
transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height);
transform = CGAffineTransformRotate(transform, M_PI);
break;
case UIImageOrientationDownMirrored: //EXIF = 4
transform = CGAffineTransformMakeTranslation(0.0, imageSize.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
break;
case UIImageOrientationLeftMirrored: //EXIF = 5
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
break;
case UIImageOrientationLeft: //EXIF = 6
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(0.0, imageSize.width);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
break;
case UIImageOrientationRightMirrored: //EXIF = 7
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeScale(-1.0, 1.0);
transform = CGAffineTransformRotate(transform, M_PI / 2.0);
break;
case UIImageOrientationRight: //EXIF = 8
// Portrait Mode
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0);
transform = CGAffineTransformRotate(transform, M_PI / 2.0);
break;
default:
[NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];
}
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
if(orient == UIImageOrientationRight || orient == UIImageOrientationLeft){ CGContextScaleCTM(context,-scaleRatio,scaleRatio); CGContextTranslateCTM(context,-height,0); } 其他{ CGContextScaleCTM(context,scaleRatio,-scaleRatio); CGContextTranslateCTM(context,0,-height); }
CGContextConcatCTM(context,transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(),CGRectMake(0,0,width,height),imgRef); UIImage * imageCopy = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
return imageCopy; }