MonoTouch的:更改图像的色调,而不仅仅是饱和(Monotouch: Changing the

2019-10-17 02:36发布

我有以下MonoTouch代码可以改变Saturation ,但我想也改变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);

Answer 1:

这是一个不同的过滤器的一部分,所以你需要使用CIHueAdjust而不是CIColorControls控制色调。



Answer 2:

下面是我落得这样做添加色相:

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

然而,这并不能在视网膜显示设备的工作,返回的图像是正确缩放。



文章来源: Monotouch: Changing the Hue of an image, not just Saturation