UIImageをグレースケールにする多くのチュートリアルをネット上で見つけることができます。しかし、UIImageを少し暗くして、まだカラフルにしたいだけです。これは可能ですか?はいの場合、サンプルソースをいくつか教えてください。
ありがとう。
UIImageをグレースケールにする多くのチュートリアルをネット上で見つけることができます。しかし、UIImageを少し暗くして、まだカラフルにしたいだけです。これは可能ですか?はいの場合、サンプルソースをいくつか教えてください。
ありがとう。
CoreImageフィルターを調査する必要があります-これがAppleDocsです
(...または、Attilaの答えに従うだけで、はるかに簡単になります!)
Zenoxのおかげで、このソリューションは正常に機能します。
+ (UIImage *)colorizeImage:(UIImage *)image withColor:(UIColor *)color {
UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, 0, -area.size.height);
CGContextSaveGState(context);
CGContextClipToMask(context, area, image.CGImage);
[color set];
CGContextFillRect(context, area);
CGContextRestoreGState(context);
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextDrawImage(context, area, image.CGImage);
UIImage *colorizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return colorizedImage;
}