我正在使用AForge.net进行频道过滤,我有3个按钮,红色,蓝色和绿色。 当我点击红色按钮时,它将应用红色通道的过滤器。但是,当我继续点击蓝色按钮时,它将与红色重叠,图像变暗。
有人知道如何在点击蓝色时“处理”红色通道,反之亦然,以便过滤器不会相互重叠吗?下面是我的代码片段。
private void redchannel_Click_1(object sender, EventArgs e)
{
try
{
pictureBox1.Image = pic;
pictureBox2.Image = pic2;
// create filter
ChannelFiltering filter = new ChannelFiltering();
// set channels' ranges to keep
filter.Red = new IntRange(0, 255);
filter.Green = new IntRange(255, 255);
filter.Blue = new IntRange(255, 255);
// apply the filter
filter.ApplyInPlace(pic2);
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
private void bluechannel_Click_1(object sender, EventArgs e)
{
try
{
pictureBox1.Image = pic;
pictureBox2.Image = pic2;
// create filter
ChannelFiltering filter = new ChannelFiltering();
// set channels' ranges to keep
filter.Red = new IntRange(255, 255);
filter.Green = new IntRange(255, 255);
filter.Blue = new IntRange(0, 255);
// apply the filter
filter.ApplyInPlace(pic2);
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
private void greenchannel_Click_1(object sender, EventArgs e)
{
try
{
pictureBox1.Image = pic;
pictureBox2.Image = pic2;
// create filter
ChannelFiltering filter = new ChannelFiltering();
// set channels' ranges to keep
filter.Red = new IntRange(255, 255);
filter.Green = new IntRange(0, 255);
filter.Blue = new IntRange(255, 255);
// apply the filter
filter.ApplyInPlace(pic2);
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
答案 0 :(得分:2)
您需要存储原始图像以及可能修改的显示图像。在原件上执行计算并使用显示图像显示它们。切勿改变原件,只改变显示图像。
答案 1 :(得分:1)
我最好的猜测是你正在做的是你将pic2初始化为原始图片的副本。然后你继续添加过滤器到pic2。所以会发生什么是你有干净的图像,然后应用第一个过滤器,第二个过滤器等等。
我会改变:
pictureBox1.Image = pic;
pictureBox2.Image = pic2;
的
pictureBox1.Image = pic;
pictureBox2.Image = pic.clone();
另一件事是你可能想要将所有3个按钮指向同一个功能。目前3种功能中有90%是代码重复。维护的噩梦。
更好的解决方案是: 你可以做的另一种方法是保持每个按钮分开(3 btn点击功能),你可以用红色,绿色和绿色调用新的过滤功能。蓝色作为参数。