1

I have a image and want to create a black tinted image of same as shown below:

Original Image Tinted Image

I have a view and a image view as it's subview. The alpha of Image view is 0.5 and its tint color to Black color. Also the background color of view was set to black color. Using this the second screenshot is generated and I want a similar output to a new UIImage.

PS: I need a new image which can stored or reused independent of background views etc.

Also I have tried following so check before reporting duplicate:

How would I tint an image programatically on the iPhone?

Overlaying a UIImage with a color?

Making a UIImageView grey

iPhone: How to Dynamically Color a UIImage

I've also tried getting image from a view but that does not help as I've more components in view not shows here.

Community
  • 1
  • 1
meteors
  • 1,747
  • 3
  • 20
  • 40
  • What didn't work with those other solutions you tried? – Wain Mar 29 '15 at 15:42
  • The first one does not give a new image but just uses UIIimageView's drawRect method to show the same image as tinted. In latter ones most of the images I got were completely including the accepted answer. – meteors Mar 29 '15 at 18:28
  • Are you trying to tint the camera image? I ask because in your sample images both cameras are white. – Rivera Jul 29 '15 at 13:40
  • No the camera image is above the tinted image. It's not part of main image. It's actually just a button to select the image in my app. I forgot to remove it from my example. – meteors Jul 29 '15 at 17:42

1 Answers1

1

iPhone - flattening a UIImageView and subviews to image = blank image might help you with your problem. The idea is to "render in context" a UIView object with 2 subviews (the image, and the black overlay view) to get an image. If you have more subviews which you do not want in the image, simple hide them when rendering.

Community
  • 1
  • 1
dariaa
  • 6,285
  • 4
  • 42
  • 58
  • Getting image from view seems too naive solution to me. Is there any other efficient solution to this? Thanks for answering, but my view has many objects (labels, buttons etc) so hiding each of them and un hiding seems a bit impractical. – meteors Mar 29 '15 at 18:35
  • Agree, that might be impractical, then why don't go for approach described here in the 2d second answer to this question http://stackoverflow.com/questions/845278/overlaying-a-uiimage-with-a-color ? – dariaa Mar 30 '15 at 10:44