1

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] initWithRed:0.0 green:0.0 blue:1.0 alpha:1.0];

and an image it just returns it as completely blackened!

Zigsaz
  • 435
  • 3
  • 15
  • Just out of curiosity, could you try sending it [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; ? – Daniel G. Wilson Aug 03 '11 at 00:54
  • 2
    Why are you drawing the image using a burn mode over a fresh context? That's surely not going to produce the correct results. – Lily Ballard Aug 03 '11 at 00:58
  • @XenElement Same result, it becomes completely black – Zigsaz Aug 03 '11 at 00:58
  • @Kevin Ballard I adapted the code from what I found online, its the only way I know how to colorize an image – Zigsaz Aug 03 '11 at 01:00
  • 1
    Check this post out http://stackoverflow.com/questions/1223340/iphone-how-do-you-color-an-image – Hadi Aug 03 '11 at 02:25
  • The code I gave does indeed work, but the color was not being initialized correctly in my code. Sorry! – Zigsaz Aug 03 '11 at 03:27
  • @8BitAce: Define "colorize". There's a couple of different possible meanings. There's also some sample code for two of the techniques available at https://github.com/kballard/MGImageUtilities and https://github.com/mattgemmell/MGImageUtilities – Lily Ballard Aug 03 '11 at 05:01

0 Answers0