码迷,mamicode.com
首页 > Windows程序 > 详细

C# (灰度)加权平均法将图片转换为灰度图

时间:2016-10-09 13:40:47      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

        private Bitmap ToG(string file)
        {
            using (Bitmap o = new Bitmap(file))
            {
                Bitmap g = new Bitmap(o.Width, o.Height);
                for (int i = 0; i < o.Width; i++)
                {
                    for (int j = 0; j < o.Height; j++)
                    {
                        Color c = o.GetPixel(i, j);
                        //灰度加权平均法公式
                            int rgb = (int)(c.R * 0.299 + c.G * 0.587 + c.B * 0.114);
                        g.SetPixel(i, j, Color.FromArgb(rgb, rgb, rgb));
                    }
                }
                return g;
            }
        }

 

C# (灰度)加权平均法将图片转换为灰度图

标签:

原文地址:http://www.cnblogs.com/wjshan0808/p/5941323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!