Skip to content

Commit 37bf1e4

Browse files
committed
Added static helper function
1 parent c7c5d08 commit 37bf1e4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

QRCoder/ArtQRCode.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System;
44
using System.Drawing;
55
using System.Drawing.Drawing2D;
6+
using static QRCoder.ArtQRCode;
7+
using static QRCoder.QRCodeGenerator;
68

79
// pull request raised to extend library used.
810
namespace QRCoder
@@ -231,6 +233,38 @@ public enum QuietZoneStyle
231233
Flat
232234
}
233235
}
236+
237+
public static class ArtQRCodeHelper
238+
{
239+
/// <summary>
240+
/// Helper function to create an ArtQRCode graphic with a single function call
241+
/// </summary>
242+
/// <param name="plainText">Text/payload to be encoded inside the QR code</param>
243+
/// <param name="pixelsPerModule">Amount of px each dark/light module of the QR code shall take place in the final QR code image</param>
244+
/// <param name="darkColor">Color of the dark modules</param>
245+
/// <param name="lightColor">Color of the light modules</param>
246+
/// <param name="backgroundColor">Color of the background</param>
247+
/// <param name="eccLevel">The level of error correction data</param>
248+
/// <param name="forceUtf8">Shall the generator be forced to work in UTF-8 mode?</param>
249+
/// <param name="utf8BOM">Should the byte-order-mark be used?</param>
250+
/// <param name="eciMode">Which ECI mode shall be used?</param>
251+
/// <param name="requestedVersion">Set fixed QR code target version.</param>
252+
/// <param name="backgroundImage">A bitmap object that will be used as background picture</param>
253+
/// <param name="pixelSizeFactor">Value between 0.0 to 1.0 that defines how big the module dots are. The bigger the value, the less round the dots will be.</param>
254+
/// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
255+
/// <param name="quietZoneRenderingStyle">Style of the quiet zones</param>
256+
/// <param name="finderPatternImage">Optional image that should be used instead of the default finder patterns</param>
257+
/// <returns>QRCode graphic as bitmap</returns>
258+
public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, ECCLevel eccLevel, bool forceUtf8 = false,
259+
bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap backgroundImage = null, double pixelSizeFactor = 0.8,
260+
bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Flat, Bitmap finderPatternImage = null)
261+
{
262+
using (var qrGenerator = new QRCodeGenerator())
263+
using (var qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
264+
using (var qrCode = new ArtQRCode(qrCodeData))
265+
return qrCode.GetGraphic(pixelsPerModule, darkColor, lightColor, backgroundColor, backgroundImage, pixelSizeFactor, drawQuietZones, quietZoneRenderingStyle, finderPatternImage);
266+
}
267+
}
234268
}
235269

236270
#endif

0 commit comments

Comments
 (0)