R = D*Sa
:目標(biāo)色 = 原色*目標(biāo)色的透明度
R
--result
S
--原色
D
--目標(biāo)色
Ra
、Sa
、Da
分別為三種顏色的透明度
- (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;
}
原圖
設(shè)置 blendMode 為 kCGBlendModeDestinationIn
targetColor為RGB(255,115,25)
轉(zhuǎn)換后的圖片