0

UIImageをグレースケールにする多くのチュートリアルをネット上で見つけることができます。しかし、UIImageを少し暗くして、まだカラフルにしたいだけです。これは可能ですか?はいの場合、サンプルソースをいくつか教えてください。

ありがとう。

4

2 に答える 2

1

CoreImageフィルターを調査する必要があります-これがAppleDocsです

(...または、Attilaの答えに従うだけで、はるかに簡単になります!)

于 2013-01-15T13:43:40.667 に答える
1

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;
}
于 2013-01-16T09:00:00.583 に答える