diff --git a/SShot/Program.cs b/SShot/Program.cs index f142b0f..6d8e9dc 100644 --- a/SShot/Program.cs +++ b/SShot/Program.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using System.Runtime.InteropServices; namespace SShot { static class Program { @@ -25,16 +26,26 @@ namespace SShot { Bitmap captureBitmap = new Bitmap(captureRectangle.Width, captureRectangle.Height, PixelFormat.Format32bppArgb); Graphics captureGraphics = Graphics.FromImage(captureBitmap); captureGraphics.CopyFromScreen(captureRectangle.Left, captureRectangle.Top, 0, 0, captureRectangle.Size); + toGrayscale(captureBitmap); captureBitmap.Save(filename, ImageFormat.Png); - } - catch (Exception ex) { + } catch (Exception ex) { if (args.Length > 0) { - if (args[0] != "-QuietErrors") { + if (args[0] != "-QuietErrors") { MessageBox.Show(ex.Message); } } } } + private static void toGrayscale(Bitmap bmp) { + for (int y = 0; y < bmp.Height; y++) { + for (int x = 0; x < bmp.Width; x++) { + var c = bmp.GetPixel(x, y); + int rgb = (c.R + c.G + c.B) / 3; + + bmp.SetPixel (x,y,Color.FromArgb(c.A, rgb,rgb,rgb)); + } + } + } } }