所以我有一个功能,它需要 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);
}
它无声地崩溃。我认为这可能是一个内存问题?该方法也被异步调用。