Add gray scale conversion
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace SShot {
|
namespace SShot {
|
||||||
static class Program {
|
static class Program {
|
||||||
@@ -25,9 +26,9 @@ namespace SShot {
|
|||||||
Bitmap captureBitmap = new Bitmap(captureRectangle.Width, captureRectangle.Height, PixelFormat.Format32bppArgb);
|
Bitmap captureBitmap = new Bitmap(captureRectangle.Width, captureRectangle.Height, PixelFormat.Format32bppArgb);
|
||||||
Graphics captureGraphics = Graphics.FromImage(captureBitmap);
|
Graphics captureGraphics = Graphics.FromImage(captureBitmap);
|
||||||
captureGraphics.CopyFromScreen(captureRectangle.Left, captureRectangle.Top, 0, 0, captureRectangle.Size);
|
captureGraphics.CopyFromScreen(captureRectangle.Left, captureRectangle.Top, 0, 0, captureRectangle.Size);
|
||||||
|
toGrayscale(captureBitmap);
|
||||||
captureBitmap.Save(filename, ImageFormat.Png);
|
captureBitmap.Save(filename, ImageFormat.Png);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
if (args.Length > 0) {
|
if (args.Length > 0) {
|
||||||
if (args[0] != "-QuietErrors") {
|
if (args[0] != "-QuietErrors") {
|
||||||
MessageBox.Show(ex.Message);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user