private ImageMagick.MagickImage originalMagickImage = null; // 图层图像修改前的状态 //点击状态下饱和度调节 private void MouseButtonDown(object sender, MouseButtonEventArgs args) { if (down == null) { return; } originalMagickImage = new ImageMagick.MagickImage(bitmap); ImageMagick.Percentage brightness = new ImageMagick.Percentage(100); // 100%表示不改变该属性 ImageMagick.Percentage saturation = new ImageMagick.Percentage(50); ImageMagick.Percentage hue = new ImageMagick.Percentage(100); // 滑动条范围值0%~200% ImageMagick.MagickImage newImage = new ImageMagick.MagickImage(originalMagickImage); // 相当于深复制 newImage.Modulate(brightness, saturation, hue); // 重新给Image控件赋值新图像 down = newImage.ToBitmapSource(); Source = down; originalMagickImage.Dispose(); }
/// <summary> /// 色相、饱和度、亮度、对比度 /// </summary> /// <param name="sourceimg"></param> /// <param name="threshold"></param> /// <returns></returns> public static Bitmap HSLC(Image sourceimg, int H, int S, int L, int C) { if (sourceimg != null) { ImageMagick.MagickImage originalMagickImage; originalMagickImage = new ImageMagick.MagickImage((Bitmap)sourceimg); // 只调整图像的Hue色相值 ImageMagick.Percentage brightness = new ImageMagick.Percentage(L); // 100%表示不改变该属性 ImageMagick.Percentage saturation = new ImageMagick.Percentage(S); ImageMagick.Percentage hue = new ImageMagick.Percentage(H); // 滑动条范围值0%~200% ImageMagick.MagickImage newImage = new ImageMagick.MagickImage(originalMagickImage); // 相当于深复制 newImage.Modulate(brightness, saturation, hue); // 重新给Image控件赋值新图像 Bitmap bitmap1 = newImage.ToBitmap(); Bitmap bitmap = Contrast(bitmap1, C); return(bitmap); } else { return((Bitmap)sourceimg); } }
public void loaded(object sender, EventArgs args) { if (originalMagickImage == null) { up = Source; if (down == null) { bitmap = ImageSourceToBitmap(this.Source); // img是前台Image控件 new Task(new Action(() => { originalMagickImage = new ImageMagick.MagickImage(bitmap); ImageMagick.Percentage brightness = new ImageMagick.Percentage(100); // 100%表示不改变该属性 ImageMagick.Percentage saturation = new ImageMagick.Percentage(50); ImageMagick.Percentage hue = new ImageMagick.Percentage(100); // 滑动条范围值0%~200% ImageMagick.MagickImage newImage = new ImageMagick.MagickImage(originalMagickImage); // 相当于深复制 newImage.Modulate(brightness, saturation, hue); // 重新给Image控件赋值新图像 down = newImage.ToBitmapSource(); })).Start(); } } }
private void ExecuteModulate(XmlElement element, MagickImage image) { Hashtable arguments = new Hashtable(); foreach (XmlAttribute attribute in element.Attributes) { arguments[attribute.Name] = Variables.GetValue<Percentage>(attribute); } if (OnlyContains(arguments, "brightness")) image.Modulate((Percentage)arguments["brightness"]); else if (OnlyContains(arguments, "brightness", "saturation")) image.Modulate((Percentage)arguments["brightness"], (Percentage)arguments["saturation"]); else if (OnlyContains(arguments, "brightness", "saturation", "hue")) image.Modulate((Percentage)arguments["brightness"], (Percentage)arguments["saturation"], (Percentage)arguments["hue"]); else throw new ArgumentException("Invalid argument combination for 'modulate', allowed combinations are: [brightness] [brightness, saturation] [brightness, saturation, hue]"); }
public void Test_Modulate() { using (MagickImage image = new MagickImage(Files.TestPNG)) { image.Modulate(new Percentage(70), new Percentage(30)); #if Q8 ColorAssert.AreEqual(new MagickColor("#743e3e"), image, 25, 70); ColorAssert.AreEqual(new MagickColor("#0b0b0b"), image, 25, 40); ColorAssert.AreEqual(new MagickColor("#1f3a1f"), image, 75, 70); ColorAssert.AreEqual(new MagickColor("#5a5a5a"), image, 75, 40); ColorAssert.AreEqual(new MagickColor("#3e3e74"), image, 125, 70); ColorAssert.AreEqual(new MagickColor("#a8a8a8"), image, 125, 40); #elif Q16 || Q16HDRI ColorAssert.AreEqual(new MagickColor(OpenCLValue.Get("#72803da83da8", "#747a3eb83eb8")), image, 25, 70); ColorAssert.AreEqual(new MagickColor(OpenCLValue.Get("#0b2d0b2d0b2d", "#0b5f0b5f0b5f")), image, 25, 40); ColorAssert.AreEqual(new MagickColor(OpenCLValue.Get("#1ef3397a1ef3", "#1f7c3a781f7c")), image, 75, 70); ColorAssert.AreEqual(new MagickColor(OpenCLValue.Get("#592d592d592d", "#5ab75ab75ab7")), image, 75, 40); ColorAssert.AreEqual(new MagickColor(OpenCLValue.Get("#3da83da87280", "#3eb83eb8747a")), image, 125, 70); ColorAssert.AreEqual(new MagickColor(OpenCLValue.Get("#a5aea5aea5ae", "#a88ba88ba88b")), image, 125, 40); #else #error Not implemented! #endif } }