将图片实体部分改为某个颜色

- (UIImage *)changeImage:(UIImage *)image toColor:(UIColor *)color

{

UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextTranslateCTM(context, 0, image.size.height);

CGContextScaleCTM(context, 1.0, -1.0);

CGContextSetBlendMode(context, kCGBlendModeNormal);

CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);

CGContextClipToMask(context, rect, image.CGImage);

[color setFill];

CGContextFillRect(context, rect);

UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return newImage;

}

你可能感兴趣的:(将图片实体部分改为某个颜色)