iOS - adjust hue of UIImage

拟墨画扇 提交于 2019-12-13 05:28:06

问题


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?


回答1:


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

CIHueAdjust filter




回答2:


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



来源:https://stackoverflow.com/questions/8493231/ios-adjust-hue-of-uiimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!