0

Is it possible to adjust Hue of the UIImage/CGContextRef? I have tried to blend Context with Color and Hue blend mode but result was wrong.

Should I convert RGB to HSB, adjust HSB and convert back?

Martin Pilch
  • 3,245
  • 3
  • 38
  • 61

2 Answers2

1

I have found solution. I have simply converted color of each pixel to HSB, adjusted hue and converted back to RBG:

//convert to HSB
CGFloat h, s, l, a;
UIColor *color = [UIColor colorWithRed:r green:g blue:b alpha:1.0f];  
[color getHue:&h saturation:&s brightness:&l alpha:&a];

//adjust hue
h *= amount;

//convert back to RGB
color = [UIColor colorWithHue:h saturation:s brightness:l alpha:1.0f];
[color getRed:&r green:&g blue:&b alpha:&a];

It is not fastest solution but it is simple

Martin Pilch
  • 3,245
  • 3
  • 38
  • 61
1

For iOS 5, you can use core image filter name CIHueAdjust.

CIHueAdjust filter

user523234
  • 14,323
  • 10
  • 62
  • 102