繁体   English   中英

上色UIImage的更快方法?

[英]Faster way to color the UIImage?

我正在使用下面的代码为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();

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM