Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Colorize a gray scale image

Hi everyone:

In this little app I'm working on, I need a bunch of buttons, each with its own color. One way, of course, is to make background images for those buttons in Photoshop and include them in the project. But I was thinking to cut down on the size of the executable file and go this route:

1. Make a gray scale image of a button's background (with reflections, etc) in Photoshop and save it as PNG.

2. Include only that gray scale PNG into my Xcode project and work with it.

So the question is, how do I dynamically "colorize" a gray scale image loaded in UImage? Is it possible at all? Or, if not, is there any way to change "hue" and "saturation" on an image?

MacBook Pro 17", 2.66 GHz i7, 4GB 1067 DDR3 RAM, OS X 10.6.4 /// iPhone 4, 32GB, iOS 4

Posted on Feb 11, 2011 5:32 PM

Reply
Question marked as Best reply

Posted on Feb 11, 2011 7:01 PM

Den,

take a look at https://github.com/mattgemmell/MGImageUtilities - especially the UIImage+Tint files.

Andreas User uploaded file
2 replies

Feb 11, 2011 10:23 PM in response to Andreas Amann

Thanks for the link. While researching I actually came up with a similar code myself:

UIImage *imageReddish = [self tintedImageUsingColor:imageGrayScale forColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.8]];
+(UIImage)tintedImageUsingColor:(UIImage)image forColor:(UIColor *)tintColor
{
//Apply tint to the 'image'
UIGraphicsBeginImageContext(image.size);
CGRect drawRect = CGRectMake(0, 0, image.size.width, image.size.height);
[image drawInRect:drawRect];
[tintColor set];
UIRectFillUsingBlendMode(drawRect, kCGBlendModeSourceAtop);
UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return tintedImage;
}


But the problem with tinting is that it blows out all midtones in a gray scale image and the resulting colors look more of less all the same.

So I guess there's no easy way to do it,hah? Other than digging into actual image pixels ...

Colorize a gray scale image

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.