0

我可以在网上找到许多制作 UIImage 灰度的教程。但我只希望 UIImage 稍微暗一些,并且仍然色彩鲜艳。这可能吗?如果是,请给我一些示例来源。

谢谢。

4

2 回答 2

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 回答
1

您应该调查 Core Image 过滤器 - 这里是Apple Docs

(......或者你可以按照阿提拉的回答,简单得多!)

于 2013-01-15T13:43:40.667 回答