应用程序在图像捕获中崩溃
Posted
技术标签:
【中文标题】应用程序在图像捕获中崩溃【英文标题】:App crash in image capturing 【发布时间】:2014-03-14 12:55:32 【问题描述】:我在应用程序中捕获图像,我的应用程序收到内存警告和应用程序崩溃 以下是正在使用的代码...请帮助。 这个应用程序就像从图库中挑选图像并为它们添加动画。在动画运行时将捕获图像并将它们制作成视频。
在制作动画时捕捉图像时出现内存警告..
-(void)captureImage:(NSTimer*) t
NSLog(@"captureImage");
// Create a graphics context with the target size
// On ios 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
CGSize imageSize = CGSizeZero;
UIInterfaceOrientation orientation =
[UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsPortrait(orientation))
imageSize = [UIScreen mainScreen].bounds.size;
NSLog(@"imageSize:%@ ",NSStringFromCGSize(imageSize));
else
imageSize =
CGSizeMake([UIScreen mainScreen].bounds.size.height,
[UIScreen mainScreen].bounds.size.width);
//CGSizeMake(animatedImgView.frame.size.width, animatedImgView.frame.size.height);//
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
for (UIWindow *window in [[UIApplication sharedApplication] windows])
CGContextSaveGState(context);
CGContextTranslateCTM(context, window.center.x, window.center.y);
CGContextConcatCTM(context, window.transform);
CGContextTranslateCTM(context,
-window.bounds.size.width * window.layer.anchorPoint.x,
-window.bounds.size.height * window.layer.anchorPoint.y);
if (orientation == UIInterfaceOrientationLandscapeLeft)
CGContextRotateCTM(context, M_PI_2);
CGContextTranslateCTM(context, 0, -imageSize.width);
else if (orientation == UIInterfaceOrientationLandscapeRight)
CGContextRotateCTM(context, -M_PI_2);
CGContextTranslateCTM(context, -imageSize.height, 0);
else if (orientation == UIInterfaceOrientationPortraitUpsideDown)
CGContextRotateCTM(context, M_PI);
CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);
if
([window
respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];
//[animatedImgView drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];
else
//[window.layer.presentationLayer renderInContext:context];
CGContextRestoreGState(context);
// @autoreleasepool
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[savedImages addObject:image];
image = nil;
//
感谢您的帮助...
【问题讨论】:
【参考方案1】:我认为将图像设置为零是不够的。看: The following graphical code tagged as Leak by iOS ARC
导致异常的另一个原因可能是内存中有很多图像。它们存储在哪里?文件系统?数据库?内存?
【讨论】:
以上是关于应用程序在图像捕获中崩溃的主要内容,如果未能解决你的问题,请参考以下文章
当我在 Redmi 7A 上启动相机拍照时应用程序崩溃。也无法在 UncaughtException 处理程序中捕获崩溃