欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#彩色圖片灰度化算法實(shí)例

 更新時(shí)間:2014年10月12日 10:28:12   投稿:shichen2014  
這篇文章主要介紹了C#彩色圖片灰度化算法,以實(shí)例形式對(duì)灰度化算法進(jìn)行了較為詳細(xì)的介紹,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#彩色圖片灰度化實(shí)現(xiàn)方法。分享給大家供大家參考。具體方法如下:

主要功能代碼如下:

復(fù)制代碼 代碼如下:
public static Bitmap MakeGrayscale(Bitmap original)

{

    //create a blank bitmap the same size as original

    Bitmap newBitmap = new Bitmap(original.Width, original.Height);

    //get a graphics object from the new image

    Graphics g = Graphics.FromImage(newBitmap);

    //create the grayscale ColorMatrix

    System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(

       new float[][]

      {

         new float[] {.3f, .3f, .3f, 0, 0},

         new float[] {.59f, .59f, .59f, 0, 0},

         new float[] {.11f, .11f, .11f, 0, 0},

         new float[] {0, 0, 0, 1, 0},

         new float[] {0, 0, 0, 0, 1}

      });

    //create some image attributes

    System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();

    //set the color matrix attribute

    attributes.SetColorMatrix(colorMatrix);

    //draw the original image on the new image

    //using the grayscale color matrix

    g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);

    //dispose the Graphics object

    g.Dispose();

    return newBitmap;

}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論