I'm trying to create a mask from an image with a transparent background. I want to create a new UIImage where any pixel that has > 0 alpha to turn gray.
Asked
Active
Viewed 1,578 times
1
-
What part of the process are you having trouble with? Show us the code you've written so far and we can help you better. – user1118321 Nov 14 '13 at 05:40
-
Possible duplicate of http://stackoverflow.com/questions/8577567/monotouch-convert-color-uiimage-with-alpha-to-grayscale-and-blur – Hussain Shabbir Nov 14 '13 at 06:39
-
2I realize the information I provided is sparse, but I don't think that invalidates my question. I have a UIImageView of a present. I want the present to show a gray mask until touched, then the original image is shown. I'm pretty sure the objective is clear. I would provide code but it would simply be setting an image. And the referenced duplicate is concerning MonoTouch, the answer is in C#. – user Nov 14 '13 at 21:41
1 Answers
6
You can load an image with rendering mode UIImageRenderingModeAlwaysTemplate which draws the image as a template image, ignoring its color information.
[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
Then set the tintColor of the container to gray
yourImageView.tintColor = [UIColor grayColor];

peko
- 11,267
- 4
- 33
- 48