【发布时间】:2014-02-12 09:20:05
【问题描述】:
我需要用纯色覆盖一个小 png。 我使用的代码是:
- (UIImage *)overlayWithColor:(UIColor *)overlayColor {
UIGraphicsBeginImageContext(self.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[overlayColor setFill];
CGContextTranslateCTM(context, 0, self.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextDrawImage(context, rect, self.CGImage);
CGContextClipToMask(context, rect, self.CGImage);
CGContextAddRect(context, rect);
CGContextDrawPath(context,kCGPathFill);
UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return coloredImg;
}
但结果不是很流畅...这里是原始图像(黑色)和带有叠加层的图像(白色)
【问题讨论】:
标签: ios uiimage core-graphics