From b692674f38e616f3415acc3998fddfdfeea4061f Mon Sep 17 00:00:00 2001 From: JKlingen Date: Wed, 6 Feb 2013 22:11:21 +0000 Subject: [PATCH] added CreateMonochrome(Image), which creates a black/white version of the image (not accessible via UI yet, needs some more testing) git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2466 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/ImageHelper.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index c93c05226..0ac5739c5 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -967,6 +967,27 @@ namespace GreenshotPlugin.Core { return bb.Bitmap; } } + + /// + /// Returns a b/w of Bitmap + /// + /// Bitmap to create a b/w off + /// b/w bitmap + public static Bitmap CreateMonochrome(Image sourceImage) { + using (BitmapBuffer bb = new BitmapBuffer(sourceImage, true)) { + bb.Lock(); + for (int y = 0; y < bb.Height; y++) { + for (int x = 0; x < bb.Width; x++) { + Color color = bb.GetColorAt(x, y); + int colorBrightness = (color.R+color.G+color.B > 382) ? 255 : 0; + Color monoColor = Color.FromArgb(color.A, colorBrightness, colorBrightness, colorBrightness); + bb.SetColorAt(x, y, monoColor); + } + } + bb.Unlock(); + return bb.Bitmap; + } + } /// /// Create a new bitmap where the sourceBitmap has a Simple border around it