【问题标题】:CGContextDrawImage returning bad accessCGContextDrawImage 返回错误的访问
【发布时间】:2010-03-25 03:33:45
【问题描述】:

我已经尝试混合两个 UIImage 大约 2 天了,但我遇到了一些 BAD_ACCESS 错误。首先,我有两个方向相同的图像,基本上我使用 CoreGraphics 来进行混合。

有一个奇怪的细节,每次我修改代码,第一次在设备上编译和运行它时,我都可以毫无困难地做任何我想做的事情。重新启动应用程序后,出现错误并关闭程序。

谁能给我一盏灯?我尝试动态访问 baseImage 大小,但它也给了我不好的访问权限。

这里是我如何进行混合的 sn-p。

 UIGraphicsBeginImageContext(CGSizeMake(320, 480));
 CGContextRef context = UIGraphicsGetCurrentContext();

 CGContextTranslateCTM(context, 0, 480);
 CGContextScaleCTM(context, 1.0, -1.0);

 CGContextDrawImage(context, rect, [baseImage CGImage]);
 CGContextSetBlendMode(context, kCGBlendModeOverlay);
 CGContextDrawImage(context, rect, [tmpImage CGImage]);

 [transformationView setImage:UIGraphicsGetImageFromCurrentImageContext()];
 UIGraphicsEndImageContext();

补充:有时它可以完美地工作,没问题。有时它只是覆盖而不混合。其他的它会使 iphone 崩溃。

【问题讨论】:

    标签: iphone exc-bad-access cgcontext blending


    【解决方案1】:

    显然,主要问题是每次都编辑相同的 CGImage。为了摆脱它,我使用了

        CGImageCreateCopy(sourceImage.CGImage);
    

    现在,我不再遇到崩溃了。如果有人可以对此给出更好的解释,我将不胜感激。

    问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 2011-12-30
      相关资源
      最近更新 更多