比如说上图,其实深浅非常明显,只是 不是标准的白色和黑色.

解决方案 »

  1.   

    是想做二值化吧?R+G+B,值大的颜色深。
      

  2.   

    MARK up一下
      

  3.   


    //using System.Drawing.Imaging;private void button1_Click(object sender, EventArgs e)
    {
        Bitmap bmp = new Bitmap(@"c:\temp\Oryx Antelope.jpg");    // a color matrix to produce grayscel image
        ColorMatrix cm = new ColorMatrix(new float[][]
            {
                new float[] {.30f, .30f, .30f, 0, 0},
                new float[] {.59f, .59f, .59f, 0, 0},          // human eyes are more sensitive to green color
                new float[] {.11f, .11f, .11f, 0, 0},          // the least sensitive to blue.
                new float[] {.00f, .00f, .00f, 1, 0},
                new float[] {.00f, .00f, .00f, 0, 1}
            });    Bitmap result = new Bitmap(bmp.Width, bmp.Height);
        using (Graphics g = Graphics.FromImage(result))
        {
            // setting up color matrix and also Threshold value for binarization.
            ImageAttributes ia = new ImageAttributes();
            ia.SetColorMatrix(cm);
            ia.SetThreshold(0.5f);                    //<---        g.DrawImage(bmp, new Rectangle(0, 0, result.Width, result.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, ia);
        }
        result.Save(@"c:\temp\black&white.bmp");    result.Dispose();
        bmp.Dispose();
    }
    Hope this might help.
      

  4.   

    如为256位图,则可以直接读取该图象的调色版索引数据,对淡色赋值为百色,深色赋值为黑色,然后New一个Bitmap,将该索引付给该新图,重新显示即可!