当我想为它着色时,为什么我失去了UIImage质量

时间:2013-04-16 12:29:07

标签: iphone ios objective-c ipad uikit

我目前正在使用此代码为具有所需颜色的白色UIImage着色。但经过处理后,图像(嵌入原始图像大小合适的UIImageView)似乎失去了质量。

+ (UIImage *)imageNamed:(NSString *)name withColor:(UIColor *)theColor
{
    UIImage *baseImage = [UIImage imageNamed:name];
    UIGraphicsBeginImageContext(baseImage.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect area = CGRectMake(0, 0, baseImage.size.width, baseImage.size.height);
    CGContextScaleCTM(ctx, 1, -1);
    CGContextTranslateCTM(ctx, 0, -area.size.height);
    CGContextSaveGState(ctx);
    CGContextClipToMask(ctx, area, baseImage.CGImage);
    [theColor set];
    CGContextFillRect(ctx, area);
    CGContextRestoreGState(ctx);
    CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
    CGContextDrawImage(ctx, area, baseImage.CGImage);
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

有关如何解决此问题的任何建议吗?

0 个答案:

没有答案