更快的方式为UIImage着色?

时间:2014-01-25 14:36:23

标签: ios objective-c opengl-es uiimage quartz-2d

我使用下面的代码为UIImage着色,它运行正常。 但我面临的唯一问题是它很慢。 我可以在后台线程中运行它,但出于某种原因我想在主线程中为图像着色。 是否有任何其他解决方案可以比这个解决方案更快地为UIImage着色。 CIContext能帮忙吗?我将不胜感激任何帮助。

UIImage *coloredImage;
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, self.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextSetBlendMode(context, kCGBlendModeNormal);
[tintColor setFill];
CGContextFillRect(context, rect);CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextDrawImage(context, rect, self.CGImage);
CGContextSetBlendMode(context, kCGBlendModeDestinationIn);
CGContextDrawImage(context, rect, self.CGImage);
CGContextFlush(context);
coloredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

1 个答案:

答案 0 :(得分:0)

好像您正在设置上下文大小,然后使用颜色填充该大小并在该颜色上绘制图像。这意味着您的图像具有透明度。您是否尝试过绘制图像并设置UIImageView的背景颜色?背景颜色将显示在整个图像的后面,因此仅在图像具有透明度的位置才可见。这应该有用。