How to use a UIImage as a mask over a color in Objective-C?

Creating arbitrarily-colored icons from a black-with-alpha master image (iOS).

Up vote 1 down vote favorite share g+ share fb share tw.

I have a UIImage that is all black with an alpha channel so some parts are grayish and some parts are completely see-through. I want to use that images as a mask over some other color (let's say white to make it easy), so the final product is now a white image with parts of it transparent. I've been looking around on the Apple documentation site here: developer.apple.com/library/mac/#documen... But I'm completely new to Quartz/Core Graphics, so I don't can't really make sense of those examples.

Does anyone know of a link to some full code samples that I could use to look at? Objective-c core-graphics quartz-2d link|improve this question asked Jul 25 '11 at 23:07Philip Walton1,295319 100% accept rate.

Creating arbitrarily-colored icons from a black-with-alpha master image (iOS). // Usage: UIImage *buttonImage = UIImage ipMaskedImageNamed:@"UIButtonBarAction. Png" color:UIColor redColor; + (UIImage *)ipMaskedImageNamed:(NSString *)name color:(UIColor *)color { UIImage *image = UIImage imageNamed:name; CGRect rect = CGRectMake(0, 0, image.size.

Width, image.size. Height); UIGraphicsBeginImageContextWithOptions(rect. Size, NO, image.

Scale); CGContextRef c = UIGraphicsGetCurrentContext(); image drawInRect:rect; CGContextSetFillColorWithColor(c, color CGColor); CGContextSetBlendMode(c, kCGBlendModeSourceAtop); CGContextFillRect(c, rect); UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return result; } Credits to Ole Zorn: https://gist.github.com/1102091.

Amazing! Thank you! – Philip Walton Jul 25 '11 at 23:22.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions