在我的應用程序中,我通過點擊按鈕順序拍攝五張照片。但是,當我在照片拍攝中按下設備上的home按鈕時,應用程序像往常一樣進入後臺階段,但當我嘗試重新啓動時,應用程序崩潰。你能爲這個問題建議任何解決方案嗎?iOS應用程序在拍攝連續照片時崩潰
在此先感謝
在我的應用程序中,我通過點擊按鈕順序拍攝五張照片。但是,當我在照片拍攝中按下設備上的home按鈕時,應用程序像往常一樣進入後臺階段,但當我嘗試重新啓動時,應用程序崩潰。你能爲這個問題建議任何解決方案嗎?iOS應用程序在拍攝連續照片時崩潰
在此先感謝
你好請參閱此三種方法,這可能解決您的內存泄漏問題,實際上墜毀是由於內存泄漏,因爲有時當我們採取更多的照片分辨率高,我們使用它是我們的應用程序那麼iphone不能處理更多的內存。
還有一件事我需要說抱歉,因爲我不知道鋤頭格式化代碼。
(無效)imagePickerController:(的UIImagePickerController *)選擇器didFinishPickingMediaWithInfo:(的NSDictionary *)信息 { [拾取器dismissModalViewControllerAnimated:YES]; [picker release];
[popover dismissPopoverAnimated:YES]; [popover release]; UIImage * capturedImage = [info objectForKey:@「UIImagePickerControllerOriginalImage」];}} [self performSelector:@selector(waitUntillImageCaptured :) withObject:capturedImage afterDelay:0.2]; }
- (無效)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]; } else {[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 ratio = width/height;
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 /寬度; CGSizemageSize = 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(); (Orient == UIImageOrientationRight || orient == UIImageOrientationLeft){ CGContextScaleCTM(context,-scaleRatio,scaleRatio); CGContextTranslateCTM(context,-height,0); } else { CGContextScaleCTM(context,scaleRatio,-scaleRatio); CGContextTranslateCTM(context,0,-height); }
CGContextConcatCTM(context,transform); (UIGraphicsGetCurrentContext(),CGRectMake(0,0,width,height),imgRef); UIImage * imageCopy = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
return imageCopy; }
一些代碼請.... – IronManGill
我想看看你在viewDidLoad中做什麼。如果內存被清除,viewDidLoad可能會在重新啓動時再次運行。如果您在viewDidLoad中設置了任何委託,則它們可能不再有效。 –