From ea0174c9c305e9c006930896b6d0431d9c79a2e2 Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Fri, 21 Feb 2020 22:38:25 +0100 Subject: [PATCH] Added a QR-Code demo: press q, when your screenshot has a QR Code, when selecting a region and see some additional information. --- Greenshot/Forms/CaptureForm.cs | 46 +++++++++++++++++++++++++++++++++- Greenshot/Greenshot.csproj | 1 + 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index 0f4d19f78..2798b2aa2 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -31,6 +31,7 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Globalization; +using System.Linq; using System.Security.Permissions; using System.Threading; using System.Threading.Tasks; @@ -38,6 +39,7 @@ using System.Windows.Forms; using System.Windows.Threading; using GreenshotPlugin.IniFile; using GreenshotPlugin.Interfaces; +using ZXing; namespace Greenshot.Forms { /// @@ -321,10 +323,52 @@ namespace Greenshot.Forms { } } break; + case Keys.Q: + // create a barcode reader instance + IBarcodeReader reader = new BarcodeReader(); + // detect and decode the barcode inside the bitmap + var result = reader.Decode((Bitmap)_capture.Image); + // do something with the result + if (result != null) + { + Log.InfoFormat("Found QR of type {0} - {1}", result.BarcodeFormat, result.Text); + using var graphics = Graphics.FromImage(_capture.Image); + var boundingBox = BoundingBox(result.ResultPoints.Select(p => new Point((int) p.X, (int) p.Y))); + + using var pen = new Pen(Color.BlueViolet, 10); + using var solidBrush = new SolidBrush(Color.Green); + + using var solidWhiteBrush = new SolidBrush(Color.White); + using var font = new Font(FontFamily.GenericSerif, 12, FontStyle.Regular); + graphics.FillRectangle(solidWhiteBrush, boundingBox); + graphics.DrawRectangle(pen, boundingBox); + graphics.DrawString(result.Text, font, solidBrush, boundingBox); + + } + + break; } } - /// + /// + /// Find the list's bounding box. + /// + /// IEnumerable of Point + /// Rectangle + private Rectangle BoundingBox(IEnumerable points) + { + var x_query = from Point p in points select p.X; + int xmin = x_query.Min(); + int xmax = x_query.Max(); + + var y_query = from Point p in points select p.Y; + int ymin = y_query.Min(); + int ymax = y_query.Max(); + + return new Rectangle(xmin, ymin, xmax - xmin, ymax - ymin); + } + + /// /// The mousedown handler of the capture form /// /// diff --git a/Greenshot/Greenshot.csproj b/Greenshot/Greenshot.csproj index 7f5a822c4..dd4149892 100644 --- a/Greenshot/Greenshot.csproj +++ b/Greenshot/Greenshot.csproj @@ -18,6 +18,7 @@ +