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

首頁 > 編程 > C# > 正文

解析C#彩色圖像灰度化算法的實現代碼詳解

2020-01-24 03:17:50
字體:
來源:轉載
供稿:網友
代碼如下所示:
復制代碼 代碼如下:

        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;
        }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 重庆市| 灵台县| 玛多县| 苍梧县| 榕江县| 安乡县| 嘉峪关市| 江源县| 乌拉特中旗| 昭通市| 浮山县| 昭苏县| 锡林浩特市| 高唐县| 忻城县| 如皋市| 三门县| 长子县| 通江县| 土默特左旗| 米脂县| 大庆市| 安西县| 定远县| 洛宁县| 横山县| 博客| 桐梓县| 紫阳县| 庆阳市| 营山县| 惠水县| 无为县| 扎赉特旗| 汶川县| 宁津县| 万全县| 泌阳县| 彭阳县| 绥德县| 珠海市|