c#图像处理-灰度处理(gray)

来源:互联网 发布:sql语句 编辑:程序博客网 时间:2024/05/22 06:25
 public Bitmap GrayByPixels(Bitmap bmpcode)        {            bmpcode = new Bitmap(bmpcode);            for (int i = 0; i < bmpcode.Height; i++)            {                for (int j = 0; j < bmpcode.Width; j++)                {                    int tmpValue = GetGrayNumColor(bmpcode.GetPixel(j, i));                    bmpcode.SetPixel(j, i, Color.FromArgb(tmpValue, tmpValue, tmpValue));                }            }            return bmpcode;        }        private int GetGrayNumColor(System.Drawing.Color codecolor)        {            return (codecolor.R * 19595 + codecolor.G * 38469 + codecolor.B * 7472) >> 16;        }

处理前:

处理后: