Monotouch: Changing the Hue of an image, not just Saturation

。_饼干妹妹 提交于 2019-12-24 07:09:22

问题


I have the following MonoTouch code which can change the Saturation , but I am trying to also change the Hue.

float hue = 0;
float saturation = 1;

if (colorCtrls == null)
    colorCtrls = new CIColorControls() { 
                 Image = CIImage.FromCGImage (originalImage.CGImage) };
else
    colorCtrls.Image = CIImage.FromCGImage(originalImage.CGImage);

colorCtrls.Saturation = saturation; 

var output = colorCtrls.OutputImage;
var context = CIContext.FromOptions(null);
var result = context.CreateCGImage(output, output.Extent);

return UIImage.FromImage(result);

回答1:


It's part of a different filter so you'll need to use CIHueAdjust instead of CIColorControls to control the hue.




回答2:


Here's what I ended up doing to add Hue:

        var hueAdjust = new CIHueAdjust() {
            Image = CIImage.FromCGImage(originalImage.CGImage),
            Angle = hue // Default is 0
        };
        var output = hueAdjust.OutputImage;
        var context = CIContext.FromOptions(null);
        var cgimage = context.CreateCGImage(output, output.Extent);
        return UIImage.FromImage(cgimage);

However, this does not work on Retina devices, the image returned is scaled incorrectly.



来源:https://stackoverflow.com/questions/11753381/monotouch-changing-the-hue-of-an-image-not-just-saturation

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