2016-11-16 08:11:41 +00:00
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
// From: https://github.com/codebude/QRCoder
|
|
|
|
namespace QRCoder
|
|
|
|
{
|
|
|
|
using System;
|
|
|
|
|
2018-07-22 02:20:11 +00:00
|
|
|
public sealed class QRCode : AbstractQRCode<Bitmap>, IDisposable
|
2016-11-16 08:11:41 +00:00
|
|
|
{
|
|
|
|
public QRCode(QRCodeData data) : base(data) {}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2016-11-16 08:11:41 +00:00
|
|
|
public override Bitmap GetGraphic(int pixelsPerModule)
|
|
|
|
{
|
|
|
|
return this.GetGraphic(pixelsPerModule, Color.Black, Color.White, true);
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2016-11-16 08:11:41 +00:00
|
|
|
public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true)
|
|
|
|
{
|
|
|
|
var size = (this.QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8)) * pixelsPerModule;
|
|
|
|
var offset = drawQuietZones ? 0 : 4 * pixelsPerModule;
|
|
|
|
|
|
|
|
var bmp = new Bitmap(size, size);
|
|
|
|
var gfx = Graphics.FromImage(bmp);
|
|
|
|
for (var x = 0; x < size + offset; x = x + pixelsPerModule)
|
|
|
|
{
|
|
|
|
for (var y = 0; y < size + offset; y = y + pixelsPerModule)
|
|
|
|
{
|
|
|
|
var module = this.QrCodeData.ModuleMatrix[(y + pixelsPerModule)/pixelsPerModule - 1][(x + pixelsPerModule)/pixelsPerModule - 1];
|
|
|
|
if (module)
|
|
|
|
{
|
|
|
|
gfx.FillRectangle(new SolidBrush(darkColor), new Rectangle(x - offset, y - offset, pixelsPerModule, pixelsPerModule));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gfx.FillRectangle(new SolidBrush(lightColor), new Rectangle(x - offset, y - offset, pixelsPerModule, pixelsPerModule));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2016-11-16 08:11:41 +00:00
|
|
|
gfx.Save();
|
|
|
|
return bmp;
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2016-11-16 08:11:41 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
this.QrCodeData = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|