【问题标题】:Monotouch: Changing the Hue of an image, not just SaturationMonotouch:改变图像的色调,而不仅仅是饱和度
【发布时间】:2012-08-01 06:03:20
【问题描述】:

我有以下 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);

【问题讨论】:

    标签: ios image-processing xamarin.ios uiimage hue


    【解决方案1】:

    它是不同滤镜的一部分,因此您需要使用CIHueAdjust 而不是CIColorControls 来控制色调。

    【讨论】:

      【解决方案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);
      

      但是,这在 Retina 设备上不起作用,返回的图像缩放不正确。

      【讨论】:

      • Miguel 制作了一个关于将 CoreImage 与 MonoTouch 结合使用(包括链接过滤器)的精彩视频(在 youtube 上)。 youtube.com/watch?v=Yb2pi3tDb3c
      • 此示例不适用于 Retina 设备,返回的图像缩放不正确。
      • 请澄清:当您说“在 Retina 设备上不起作用”时,您的意思是“在使用 UINavigationController.Appearance.SetBackgroundImage 时”(根据 SO #11805628)?一般来说,我相信在将 UIImage 分配给正确设置了 Bounds 的 UIImageView 时,这段代码确实有效。
      • 对于 Retina 设备尝试 return new UIImage(cgimage, 2f, UIImageOrientation.Up);
      猜你喜欢
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 2011-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多