I am very new to the image processing. I have to implement hue effect in my iPhone application project. Therefore, I need to change the hue of UIImage
. Please provide me any sample code or tutorial link for this.
Thanks in advance
I am very new to the image processing. I have to implement hue effect in my iPhone application project. Therefore, I need to change the hue of UIImage
. Please provide me any sample code or tutorial link for this.
Thanks in advance
Swift version of Dondragmer's rotating code above
Taking Dondragmer's excellent fixed hue example as a starting point. Here is my modification, to fix the problem of transparent areas being set with the same hue.
Thanks to:
How to change hue of UIIMAGE having transparent area?
CGContextClipToMask UIImage Mask Invert Up and Down
In Apple's Swift blog, I came across this photo filtering app tutorial: https://developer.apple.com/swift/blog/?id=16
The following is the sample code edited to create a contained method that returns a UIImage with a random hue applied.
First, you need to decide if you are making an image a fixed hue, or rotating the existing hue. Examples of both are shown below.
Fixed hue
Fixing the hue can be done using the standard drawing tools - just make sure the blend mode is set to
kCGBlendModeHue
, and draw with the appropriate hue. This is derived from Nitish's solution, although I found that makingsaturation
less than1.0
had inconsistent results. This method does allow varying the alpha, but for true saturation other than 100% you will probably need a second round of drawing.Rotated hue
To rotate the hue, you need Core Image filters. The code below converts the UIImage to a CIImage, and then converts the result back to UIImage for display. Depending on where your image comes from, you may be able to avoid one or both of these steps.
Conveniently, the very first example in the Core Image Programming Guide: Using Core Image Filters uses the CIHueAdjust filter.