Iphone UIGraphicsBeginImageContextWithOptions自动崩溃,无错误
所以我有一个函数,它可以拍摄两幅图像并将它们组合起来。可能图像太大了,因为当我尝试用两个较小的图像时,效果很好,但我不确定。所以我用相机拍了一张照片,试着从相册中打开它。我使用此功能拾取图像并将其与另一图像组合:Iphone UIGraphicsBeginImageContextWithOptions自动崩溃,无错误,iphone,ios,xcode,Iphone,Ios,Xcode,所以我有一个函数,它可以拍摄两幅图像并将它们组合起来。可能图像太大了,因为当我尝试用两个较小的图像时,效果很好,但我不确定。所以我用相机拍了一张照片,试着从相册中打开它。我使用此功能拾取图像并将其与另一图像组合: - (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage { UIImage *image = nil; float scale = 0.5f;
- (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage {
UIImage *image = nil;
float scale = 0.5f;
CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), MAX(firstImage.size.height, secondImage.size.height));
NSLog(@"reached image by combining image");
//crashes here when the image has been selected from an album (secondImage).
// runs fine when the image has been taken from the camera. (secondImage).
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(newImageSize);
}
[firstImage drawAtPoint:CGPointMake(roundf((newImageSize.width-firstImage.size.width)/2),
roundf((newImageSize.height-firstImage.size.height)/2))];
UIImage *scaledImage =
[UIImage imageWithCGImage:[secondImage CGImage]
scale:scale orientation:UIImageOrientationUp];
[scaledImage drawAtPoint:CGPointMake(roundf((100)),
roundf((100)))];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
当我到达这一行时:
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(newImageSize);
}
它无声地崩溃了。我想可能是记忆问题吧?
该方法也被异步调用 我不知道你的问题的答案,但我建议你检查以下几点:
我也有同样的车祸,没错 从
好的,UIGraphicsBeginImageContextWithOptions是一条红鲱鱼
问题似乎是xxx没有被解除分配。在合并时,我不得不将图像大小减小3,然后它才停止崩溃。太大了 是的。我正在使用它们为放入的图像创建帧大小。在到达那里之前,我已经按照我的确切方法精简了代码。在代码发布中,你没有使用它们做任何事情。将图像指定给UIImageView并设置帧不会更改原始图像或图像属性返回的图像(将与原始图像相同)。前7-8行没用,你说得对。我用代码更新了我的问题。你是否检查过你是否在第1点中建议的主线程中?然后,我看不出问题,只要你在主线程中并且你正在传递一个正确的新图像大小UIGraphicsBeginImageContextWithOptions应该可以正常工作。它到底在哪一行崩溃?如果,则显示
中的条件?UIGraphicsBeginImageContext…
函数?UIGraphicsBeginImageContextWithOptions(新建图像大小,否,[[UIScreen main screen]比例]);然后在控制台中显示“Received memory warning.”。仅供将来参考如果您使用lldb调试器,那么一旦发生崩溃,您可以在右侧的框中键入。输入“bt”(用于回溯),通常您可以获得有关崩溃发生原因的更多信息。我会记得Tahnkyu MobileMon。当在“不安全”下定义委托时,我遇到了相同的问题,通过更改为“弱”将其修复。