3

I've been trying to blend two UIImage for about 2 days now and I've been getting some BAD_ACCESS errors. First of all, I have two images that have the same orientation, basically I'm using the CoreGraphics to do the blending.

One curious detail, everytime I modify the code, the first time I compile and run it on device, I get to do everything I want without any sort of trouble. Once I restart the application, I get error and the program shuts down.

Can anyone give me a light? I tried accessing the baseImage sizes dynamically, but it gives me bad access too.

Here's a snippet of how I'm doing the blending.

 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();

Complementing: Sometimes it gets to work perfectly, no problem. Sometimes it simply overlays and doesn't blend. Others it crashes the iphone.

4

1 回答 1

4

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

    CGImageCreateCopy(sourceImage.CGImage);

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

问候

于 2010-03-24T19:33:45.387 回答