System.Drawing.Imaging.ImageAttributes.SetThreshold C# (CSharp) Method

SetThreshold() public method

public SetThreshold ( float thresh ) : void
thresh float
return void
		public void SetThreshold(float thresh)
		{
			SetThreshold(thresh, ColorAdjustType.Default);
		}

Same methods

ImageAttributes::SetThreshold ( float thresh, ColorAdjustType type ) : void

Usage Example

Example #1
0
        public static Bitmap Threshold(Bitmap original)
        {
            int width = original.Width;
            int height = original.Height;
            Bitmap bmp = new Bitmap(width, height);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                ImageAttributes threshold = new ImageAttributes();
                threshold.SetThreshold(0.92f);
                //attributes.SetThreshold(0.08f);

                g.DrawImage(original, new Rectangle(0, 0, width, height),
                    0, 0, width, height, GraphicsUnit.Pixel, threshold);

                ImageAttributes invert = new ImageAttributes();
                ColorMap[] map = new ColorMap[2];
                map[0] = new ColorMap();
                map[0].OldColor = Color.Black;
                map[0].NewColor = Color.White;
                map[1] = new ColorMap();
                map[1].OldColor = Color.White;
                map[1].NewColor = Color.Black;
                invert.SetRemapTable(map);

                g.DrawImage(bmp, new Rectangle(0, 0, width, height),
                    0, 0, width, height, GraphicsUnit.Pixel, invert);
            }
            return bmp;
        }
All Usage Examples Of System.Drawing.Imaging.ImageAttributes::SetThreshold