2010-03-24 78 views
3

我一直在尝试将两个UIImage混合约2天,并且我一直在收到一些BAD_ACCESS错误。首先,我有两个具有相同方向的图像,基本上我使用CoreGraphics来进行混合。CGContextDrawImage返回错误访问

一个好奇的细节,每次我修改代码,第一次在设备上编译和运行代码时,我可以做任何我想做的事情而不会遇到任何麻烦。一旦我重新启动应用程序,就会出现错误并关闭程序。

任何人都可以给我一个灯?我试图动态访问baseImage大小,但它也给我访问不好。

这是我如何做混合的片段。

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崩溃。

回答

4

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

CGImageCreateCopy(sourceImage.CGImage); 

现在,我没有得到崩溃了。如果有人能为此提供更好的解释,我很感激。

Regards