質問

I am trying to set the threshold of an image at runtime. Currently my code looks like:

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 contains the black and white image. The problem is inside the imageAttr.SetThreshold(kryptonTrackBar1.Value / 100); line.

My trackbar max is 100 and min 0. So I should end up with numbers like 0.07 and so on while scrolling the trackbar, but the trackbar only returns the value of 0 and 1! 1 if I scroll all the way to the right!

What's wrong with it?

役に立ちましたか?

解決

How about

imageAttr.SetThreshold((float)kryptonTrackBar1.Value / 100.0f);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top