Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +(UIImage *)colorizeImage:(UIImage *)baseImage color:(UIColor *)theColor
- {
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement