国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

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

2020-01-24 02:22:29
字體:
供稿:網(wǎng)友

本文實(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ì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 濮阳县| 林口县| 景宁| 安宁市| 澳门| 平乐县| 扎兰屯市| 枣庄市| 灌阳县| 宣恩县| 长寿区| 元谋县| 怀安县| 晋州市| 海宁市| 邯郸市| 临邑县| 萝北县| 蒙自县| 齐齐哈尔市| 怀化市| 石景山区| 杭锦后旗| 开远市| 华亭县| 怀远县| 肃北| 东阿县| 宣威市| 浮山县| 永康市| 贵定县| 晋州市| 九台市| 商南县| 巴马| 灵山县| 新河县| 方正县| 西华县| 衡山县|