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; } }
时间: 2024-11-08 01:46:35