@@ -19,11 +19,27 @@ public class SvgQRCode : AbstractQRCode, IDisposable
19
19
public SvgQRCode ( ) { }
20
20
public SvgQRCode ( QRCodeData data ) : base ( data ) { }
21
21
22
+ /// <summary>
23
+ /// Returns a QR code as SVG string
24
+ /// </summary>
25
+ /// <param name="pixelsPerModule">The pixel size each b/w module is drawn</param>
26
+ /// <returns>SVG as string</returns>
22
27
public string GetGraphic ( int pixelsPerModule )
23
28
{
24
29
var viewBox = new Size ( pixelsPerModule * this . QrCodeData . ModuleMatrix . Count , pixelsPerModule * this . QrCodeData . ModuleMatrix . Count ) ;
25
30
return this . GetGraphic ( viewBox , Color . Black , Color . White ) ;
26
31
}
32
+
33
+ /// <summary>
34
+ /// Returns a QR code as SVG string with custom colors, optional quietzone and logo
35
+ /// </summary>
36
+ /// <param name="pixelsPerModule">The pixel size each b/w module is drawn</param>
37
+ /// <param name="darkColor">Color of the dark modules</param>
38
+ /// <param name="lightColor">Color of the light modules</param>
39
+ /// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
40
+ /// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
41
+ /// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
42
+ /// <returns>SVG as string</returns>
27
43
public string GetGraphic ( int pixelsPerModule , Color darkColor , Color lightColor , bool drawQuietZones = true , SizingMode sizingMode = SizingMode . WidthHeightAttribute , SvgLogo logo = null )
28
44
{
29
45
var offset = drawQuietZones ? 0 : 4 ;
@@ -32,6 +48,16 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
32
48
return this . GetGraphic ( viewBox , darkColor , lightColor , drawQuietZones , sizingMode , logo ) ;
33
49
}
34
50
51
+ /// <summary>
52
+ /// Returns a QR code as SVG string with custom colors (in HEX syntax), optional quietzone and logo
53
+ /// </summary>
54
+ /// <param name="pixelsPerModule">The pixel size each b/w module is drawn</param>
55
+ /// <param name="darkColorHex">The color of the dark/black modules in hex (e.g. #000000) representation</param>
56
+ /// <param name="lightColorHex">The color of the light/white modules in hex (e.g. #ffffff) representation</param>
57
+ /// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
58
+ /// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
59
+ /// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
60
+ /// <returns>SVG as string</returns>
35
61
public string GetGraphic ( int pixelsPerModule , string darkColorHex , string lightColorHex , bool drawQuietZones = true , SizingMode sizingMode = SizingMode . WidthHeightAttribute , SvgLogo logo = null )
36
62
{
37
63
var offset = drawQuietZones ? 0 : 4 ;
@@ -40,16 +66,44 @@ public string GetGraphic(int pixelsPerModule, string darkColorHex, string lightC
40
66
return this . GetGraphic ( viewBox , darkColorHex , lightColorHex , drawQuietZones , sizingMode , logo ) ;
41
67
}
42
68
69
+ /// <summary>
70
+ /// Returns a QR code as SVG string with optional quietzone and logo
71
+ /// </summary>
72
+ /// <param name="viewBox">The viewbox of the QR code graphic</param>
73
+ /// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
74
+ /// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
75
+ /// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
76
+ /// <returns>SVG as string</returns>
43
77
public string GetGraphic ( Size viewBox , bool drawQuietZones = true , SizingMode sizingMode = SizingMode . WidthHeightAttribute , SvgLogo logo = null )
44
78
{
45
79
return this . GetGraphic ( viewBox , Color . Black , Color . White , drawQuietZones , sizingMode , logo ) ;
46
80
}
47
81
82
+ /// <summary>
83
+ /// Returns a QR code as SVG string with custom colors and optional quietzone and logo
84
+ /// </summary>
85
+ /// <param name="viewBox">The viewbox of the QR code graphic</param>
86
+ /// <param name="darkColor">Color of the dark modules</param>
87
+ /// <param name="lightColor">Color of the light modules</param>
88
+ /// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
89
+ /// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
90
+ /// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
91
+ /// <returns>SVG as string</returns>
48
92
public string GetGraphic ( Size viewBox , Color darkColor , Color lightColor , bool drawQuietZones = true , SizingMode sizingMode = SizingMode . WidthHeightAttribute , SvgLogo logo = null )
49
93
{
50
94
return this . GetGraphic ( viewBox , ColorTranslator . ToHtml ( Color . FromArgb ( darkColor . ToArgb ( ) ) ) , ColorTranslator . ToHtml ( Color . FromArgb ( lightColor . ToArgb ( ) ) ) , drawQuietZones , sizingMode , logo ) ;
51
95
}
52
96
97
+ /// <summary>
98
+ /// Returns a QR code as SVG string with custom colors (in HEX syntax), optional quietzone and logo
99
+ /// </summary>
100
+ /// <param name="viewBox">The viewbox of the QR code graphic</param>
101
+ /// <param name="darkColorHex">The color of the dark/black modules in hex (e.g. #000000) representation</param>
102
+ /// <param name="lightColorHex">The color of the light/white modules in hex (e.g. #ffffff) representation</param>
103
+ /// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
104
+ /// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
105
+ /// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
106
+ /// <returns>SVG as string</returns>
53
107
public string GetGraphic ( Size viewBox , string darkColorHex , string lightColorHex , bool drawQuietZones = true , SizingMode sizingMode = SizingMode . WidthHeightAttribute , SvgLogo logo = null )
54
108
{
55
109
int offset = drawQuietZones ? 0 : 4 ;
@@ -194,26 +248,33 @@ private string CleanSvgVal(double input)
194
248
return input.ToString(System.Globalization.CultureInfo.InvariantCulture);
195
249
}
196
250
251
+ /// <summary>
252
+ /// Mode of sizing attribution on svg root node
253
+ /// </summary>
197
254
public enum SizingMode
198
255
{
199
256
WidthHeightAttribute,
200
257
ViewBoxAttribute
201
258
}
202
259
260
+ /// <summary>
261
+ /// Represents a logo graphic that can be rendered on a SvgQRCode
262
+ /// </summary>
203
263
public class SvgLogo
204
264
{
205
265
private string _logoData;
206
266
private MediaType _mediaType;
207
267
private int _iconSizePercent;
208
268
private bool _fillLogoBackground;
209
269
private object _logoRaw;
210
-
211
270
271
+
212
272
/// <summary>
213
273
/// Create a logo object to be used in SvgQRCode renderer
214
274
/// </summary>
215
275
/// <param name="iconRasterized">Logo to be rendered as Bitmap/rasterized graphic</param>
216
276
/// <param name="iconSizePercent">Degree of percentage coverage of the QR code by the logo</param>
277
+ /// <param name="fillLogoBackground">If true, the background behind the logo will be cleaned</param>
217
278
public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true)
218
279
{
219
280
_iconSizePercent = iconSizePercent;
@@ -235,6 +296,7 @@ public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBac
235
296
/// </summary>
236
297
/// <param name="iconVectorized">Logo to be rendered as SVG/vectorized graphic/string</param>
237
298
/// <param name="iconSizePercent">Degree of percentage coverage of the QR code by the logo</param>
299
+ /// <param name="fillLogoBackground">If true, the background behind the logo will be cleaned</param>
238
300
public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBackground = true)
239
301
{
240
302
_iconSizePercent = iconSizePercent;
@@ -244,30 +306,54 @@ public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBac
244
306
_logoRaw = iconVectorized;
245
307
}
246
308
309
+ /// <summary>
310
+ /// Returns the raw logo's data
311
+ /// </summary>
312
+ /// <returns></returns>
247
313
public object GetRawLogo()
248
314
{
249
315
return _logoRaw;
250
316
}
251
317
318
+ /// <summary>
319
+ /// Returns the media type of the logo
320
+ /// </summary>
321
+ /// <returns></returns>
252
322
public MediaType GetMediaType()
253
323
{
254
324
return _mediaType;
255
325
}
256
326
327
+ /// <summary>
328
+ /// Returns the logo as data-uri
329
+ /// </summary>
330
+ /// <returns></returns>
257
331
public string GetDataUri()
258
332
{
259
333
return $"data:{_mediaType.GetStringValue()};base64,{_logoData}";
260
334
}
261
335
336
+ /// <summary>
337
+ /// Returns how much of the QR code should be covered by the logo (in percent)
338
+ /// </summary>
339
+ /// <returns></returns>
262
340
public int GetIconSizePercent()
263
341
{
264
342
return _iconSizePercent;
265
343
}
344
+
345
+ /// <summary>
346
+ /// Returns if the background of the logo should be cleaned (no QR modules will be rendered behind the logo)
347
+ /// </summary>
348
+ /// <returns></returns>
266
349
public bool FillLogoBackground()
267
350
{
268
351
return _fillLogoBackground;
269
352
}
270
353
354
+ /// <summary>
355
+ /// Media types for SvgLogos
356
+ /// </summary>
271
357
public enum MediaType : int
272
358
{
273
359
[StringValue("image/png")]
0 commit comments