CGBlendMode

R = D*Sa :目标色 = 原色*目标色的透明度
R--result
S--原色
D--目标色
RaSaDa分别为三种颜色的透明度


- (UIImage *)changImageColorWithImage:(UIImage *)image  color:(UIColor *)targetColor blendModel:(CGBlendMode)mode
{
    //获取画布
    UIGraphicsBeginImageContext(image.size);
    //画笔沾取颜色
    [targetColor setFill];
    
    CGRect drawRect = CGRectMake(0, 0, image.size.width, image.size.height);
    UIRectFill(drawRect);
    [image drawInRect:drawRect blendMode:mode alpha:1];
    //获取图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return newImage;
 }
原图

设置 blendMode 为 kCGBlendModeDestinationIn targetColor为RGB(255,115,25)

转换后的图片

你可能感兴趣的:(CGBlendMode)