开发者

iOS Colorizing an Image Turns it Black

开发者 https://www.devze.com 2023-03-24 14:41 出处:网络
I have this method which I created after hooking into SBAwayView: - (UIImage *) colorizeImage:(UIImage *)img color:(UIColor *)color{

I have this method which I created after hooking into 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;
}

But when I send it the color

[[UIColor alloc] initWith开发者_Go百科Red:0.0 green:0.0 blue:1.0 alpha:1.0];

and an image it just returns it as completely blackened!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号