Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. +(UIImage *)colorizeImage:(UIImage *)baseImage color:(UIColor *)theColor
  2. {
  3. UIGraphicsBeginImageContext(baseImage.size);
  4.  
  5. CGContextRef ctx = UIGraphicsGetCurrentContext();
  6. CGRect area = CGRectMake(0, 0, baseImage.size.width, baseImage.size.height);
  7.  
  8. CGContextScaleCTM(ctx, 1, -1);
  9. CGContextTranslateCTM(ctx, 0, -area.size.height);
  10. CGContextSaveGState(ctx);
  11. CGContextClipToMask(ctx, area, baseImage.CGImage);
  12. [theColor set];
  13. CGContextFillRect(ctx, area);
  14. CGContextRestoreGState(ctx);
  15. CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
  16. CGContextDrawImage(ctx, area, baseImage.CGImage);
  17. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  18. UIGraphicsEndImageContext();
  19. return newImage;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement