Search code examples
iosiphoneipadcolors

How can I change hue of an UIImage programmatically only in few parts?


How can I change hue of an UIImage programmatically only in few parts? I have followed this link

How to programmatically change the hue of UIImage?

enter image description here

and used the same code in my application. It's working fine but the complete image hue is getting changed. According to my requirement I want to change only the tree color in the above snap. How can I do that?


Solution

  • This is a specific case of a more general problem of using masking. I assume you have some way of knowing what pixels are in the "tree" part, and which ones are not. (If not, that's a whole other question/problem).

    If so, first draw the original to the result context, then create a mask (see here: http://mobiledevelopertips.com/cocoa/how-to-mask-an-image.html), and draw the changed-hue version with the mask representing the tree active.