带轨迹栏的阈值图像

时间:2012-06-26 20:16:34

标签: c# picturebox threshold trackbar

我试图在运行时设置图像的阈值。目前我的代码如下:

ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetThreshold(kryptonTrackBar1.Value / 100);

System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pictureBox3.Image);
Graphics g = System.Drawing.Graphics.FromImage(bmp);
g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0,
                 bmp.Width, bmp.Height, GraphicsUnit.Pixel, imageAttr);
pictureBox1.Image = bmp;

picturebox3包含黑白图像。问题出在imageAttr.SetThreshold(kryptonTrackBar1.Value / 100);行内。

我的轨道栏最大值为100且最小值为0。 所以我应该在滚动轨迹栏时最终得到像0.07这样的数字,但轨迹栏只返回值0和1! 1如果我一直向右滚动!

它出了什么问题?

1 个答案:

答案 0 :(得分:3)

怎么样

imageAttr.SetThreshold((float)kryptonTrackBar1.Value / 100.0f);