CGContextDrawImage returning bad access
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 progr开发者_JS百科am 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.
Appearantly, the main problem was editing the same CGImage everytime. To get rid of it, I used
CGImageCreateCopy(sourceImage.CGImage);
Right now, I'm not getting crashes anymore. If anyone can give a better explanation for this, I appreciate.
Regards
精彩评论