这是一个快速简单的解决方案。
它使用一个功能,该功能将插件与您可以找到的帖子here。
这是函数:
public Color ToWhiteExceptYellow(Color c, int range)
{
float hueC = c.GetHue();
float e = 1.5f * range; // you can adapt this nuumber
float hueY = Color.Yellow.GetHue();
float delta = hueC - hueY;
bool ok = (Math.Abs(delta) < e);
//if (!ok) { ok = (Math.Abs(360 + delta) < e); } // include these lines ..
//if (!ok) { ok = (Math.Abs(360 - delta) < e); } // for reddish colors!
return ok ? c : Color.White;
}
它适用于黄色,但由于色调是一个环绕数字需要更多代码才能使用环绕点颜色(红色)。我已经包含了两行来提供帮助。
要使其正常工作,请更改链接帖子中的这些行:
// pick one of our filter methods
ModifyHue hueChanger = new ModifyHue(ToWhiteExceptYellow);
..和..
// we pull the bitmap from the image
Bitmap bmp = new Bitmap( (Bitmap)pictureBox1.Image); // create a copy
..和..
c = hueChanger(c, trackBar1.Value); // insert a number you like, mine go from 1-10
..和..:
// we need to re-assign the changed bitmap
pictureBox2.Image = (Bitmap)bmp; // show in a 2nd picturebox
不要忘记包含委托:
public delegate Color ModifyHue(Color c, int ch);
和 using 子句:
using System.Drawing.Imaging;
请注意,应该处理旧内容以避免泄漏图像,可能是这样:
Bitmap dummy = (Bitmap )pictureBox2.Image;
pictureBox2.Image = null;
if (dummy != null) dummy.Dispose;
// now assign the new image!
让我们看看它的工作原理:
请随意扩展。您可以更改函数的签名以包含目标颜色并添加亮度和/或饱和度范围..