Exemple #1
0
        private static void Grayscale(Bitmap source)
        {
            using (var bmp = new LockBitmap(source))
            {
                for (var y = 0; y < bmp.Height; y++)
                {
                    for (var x = 0; x < bmp.Width; x++)
                    {
                        var color        = bmp.GetPixel(x, y);
                        var minComponent = (color.R + color.G + color.B) / 3;

                        if (minComponent > 255)
                        {
                            minComponent = 255;
                        }

                        var newColor = Color.FromArgb(color.A, minComponent, minComponent, minComponent);
                        bmp.SetPixel(x, y, newColor);
                    }
                }
            }
        }
        private static void Grayscale(Bitmap source)
        {
            using (var bmp = new LockBitmap(source))
            {
                for (var y = 0; y < bmp.Height; y++)
                {
                    for (var x = 0; x < bmp.Width; x++)
                    {
                        var color = bmp.GetPixel(x, y);
                        var minComponent = (color.R + color.G + color.B) / 3;

                        if (minComponent > 255)
                        {
                            minComponent = 255;
                        }

                        var newColor = Color.FromArgb(color.A, minComponent, minComponent, minComponent);
                        bmp.SetPixel(x, y, newColor);
                    }
                }
            }
        }