Monotouch: Changing the Hue of an image, not just

2019-08-05 10:33发布

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);

2条回答
劫难
2楼-- · 2019-08-05 10:41

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.

查看更多
爷、活的狠高调
3楼-- · 2019-08-05 11:05

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

查看更多
登录 后发表回答