mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Added a QR-Code demo: press q, when your screenshot has a QR Code, when selecting a region and see some additional information.
This commit is contained in:
parent
5222d3e562
commit
ea0174c9c3
2 changed files with 46 additions and 1 deletions
|
@ -31,6 +31,7 @@ using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Permissions;
|
using System.Security.Permissions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -38,6 +39,7 @@ using System.Windows.Forms;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using GreenshotPlugin.IniFile;
|
using GreenshotPlugin.IniFile;
|
||||||
using GreenshotPlugin.Interfaces;
|
using GreenshotPlugin.Interfaces;
|
||||||
|
using ZXing;
|
||||||
|
|
||||||
namespace Greenshot.Forms {
|
namespace Greenshot.Forms {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -321,10 +323,52 @@ namespace Greenshot.Forms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Find the list's bounding box.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="points">IEnumerable of Point</param>
|
||||||
|
/// <returns>Rectangle</returns>
|
||||||
|
private Rectangle BoundingBox(IEnumerable<Point> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
/// The mousedown handler of the capture form
|
/// The mousedown handler of the capture form
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Tools.InnoSetup" version="6.0.3" GeneratePathProperty="true" />
|
<PackageReference Include="Tools.InnoSetup" version="6.0.3" GeneratePathProperty="true" />
|
||||||
|
<PackageReference Include="ZXing.Net" Version="0.16.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue