所以我有一个功能,需要2张图像并将它们组合在一起。也许图像太大了,因为当我用2个较小的图像尝试它时,它工作正常,但我不确定。所以我在相机上拍了一张照片,然后尝试从相册中打开它。我选择图像并使用此功能将其与另一个图像组合:
- (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);
}
它静静地崩溃了。我想这可能是一个记忆问题?
该方法也被异步调用。
答案 0 :(得分:1)
在合并时停止崩溃之前,我不得不将图像的大小减小3。太大了。
答案 1 :(得分:0)
我只有这个信息没有你的问题的解决方案,但我建议你检查一些事情:
答案 2 :(得分:0)
我也遇到了同样的崩溃!
来自UIGraphicsBeginImageContextWithOptions crashing
好的,UIGraphicsBeginImageContextWithOptions是一个红色的鲱鱼。 ......
似乎问题是xxx没有被解除分配。