所以我有一个函数可以拍摄两张图像并将它们组合起来。也许图像太大,因为当我尝试使用 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);
}
它无声地崩溃了。我想这可能是内存问题? 该方法也被异步调用。
最佳答案
我必须将图像的大小减小 3 才能停止合并时的崩溃。太大了。
关于iphone - UIGraphicsBeginImageContextWithOptions 无提示崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12215921/