iphone - UIGraphicsBeginImageContextWithOptions 无提示崩溃

标签 iphone ios xcode

所以我有一个函数可以拍摄两张图像并将它们组合起来。也许图像太大,因为当我尝试使用 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/

相关文章:

iPhone:如何确定 UIImage 区域的平均明暗度

iphone - 使用自定义字体

Swift 中的 JSON 错误

ios - 为每个线程创建EAGLContext可以吗?

ios - 我可以使用 OSX 10.5 编写 iOS 应用程序吗?

ios - 将元素附加到数组时遇到问题

iPhone 表格单元格标签未对齐

iphone - 将记录保存到 coreData 需要很长时间,我怎样才能更快地插入它们?

ios - 在 iOS 上未收到推送形式的 Urban Airship

ios - NSDate 是类成员 : [NSDate class] returns false?