我已经尝试了两天来混合两个UIImage图像,但是一直遇到一些BAD_ACCESS错误。首先,我有两个拥有相同方向的图像,基本上我正在使用CoreGraphics来进行混合。
一个有趣的细节是,每当我修改代码时,在设备上第一次编译和运行时,我可以顺利地做我想要的一切而不会出现任何问题。但是一旦我重新启动应用程序,就会出现错误并关闭程序。
有人能给我一点提示吗?我尝试动态访问baseImage大小,但也会导致bad access错误。
这是我如何进行混合的代码片段:
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崩溃。