Add gray scale conversion

This commit is contained in:
Jorg Tretter
2021-07-14 09:00:54 -05:00
parent ca8ffb08f4
commit 7a6c2aca01

View File

@@ -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,9 +26,9 @@ 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") {
MessageBox.Show(ex.Message);
@@ -36,5 +37,15 @@ namespace SShot {
}
}
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));
}
}
}
}
}