iOS着色图像将其变为黑色

时间:2011-08-03 00:50:32

标签: iphone ios uiimage uicolor colorize

我有这个方法,我在挂钩到SBAwayView后创建了:

- (UIImage *) colorizeImage:(UIImage *)img color:(UIColor *)color{

    NSString *name = @"badge.png";
    UIImage *img = [UIImage imageNamed:name];

    UIGraphicsBeginImageContext(img.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    [color setFill];

    CGContextTranslateCTM(context, 0, img.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    CGContextSetBlendMode(context, kCGBlendModeColorBurn);
    CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
    CGContextDrawImage(context, rect, img.CGImage);

    CGContextClipToMask(context, rect, img.CGImage);
    CGContextAddRect(context, rect);
    CGContextDrawPath(context,kCGPathFill);

    UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return coloredImg;
}

但是当我发送颜色时

[[UIColor alloc] initWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];

和图像只是将它完全变黑了!

0 个答案:

没有答案