5
5
6
6
namespace QRCoder . Xaml ;
7
7
8
+ /// <summary>
9
+ /// Represents a QR code generator that outputs QR codes as XAML DrawingImage objects.
10
+ /// </summary>
8
11
public class XamlQRCode : AbstractQRCode , IDisposable
9
12
{
10
13
/// <summary>
11
14
/// Constructor without params to be used in COM Objects connections
12
15
/// </summary>
13
16
public XamlQRCode ( ) { }
14
17
18
+ /// <summary>
19
+ /// Initializes a new instance of the <see cref="XamlQRCode"/> class with the specified <see cref="QRCodeData"/>.
20
+ /// </summary>
21
+ /// <param name="data"><see cref="QRCodeData"/> generated by the QRCodeGenerator.</param>
15
22
public XamlQRCode ( QRCodeData data ) : base ( data ) { }
16
23
24
+ /// <summary>
25
+ /// Returns a XAML DrawingImage that contains the resulting QR code.
26
+ /// </summary>
27
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
28
+ /// <returns>Returns the QR code graphic as a XAML DrawingImage.</returns>
17
29
public DrawingImage GetGraphic ( int pixelsPerModule )
18
30
=> GetGraphic ( pixelsPerModule , true ) ;
19
31
32
+ /// <summary>
33
+ /// Returns a XAML DrawingImage that contains the resulting QR code.
34
+ /// </summary>
35
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
36
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
37
+ /// <returns>Returns the QR code graphic as a XAML DrawingImage.</returns>
20
38
public DrawingImage GetGraphic ( int pixelsPerModule , bool drawQuietZones )
21
39
{
22
40
var drawableModulesCount = GetDrawableModulesCount ( drawQuietZones ) ;
23
41
var viewBox = new Size ( pixelsPerModule * drawableModulesCount , pixelsPerModule * drawableModulesCount ) ;
24
42
return GetGraphic ( viewBox , new SolidColorBrush ( Colors . Black ) , new SolidColorBrush ( Colors . White ) , drawQuietZones ) ;
25
43
}
26
44
45
+ /// <summary>
46
+ /// Returns a XAML DrawingImage that contains the resulting QR code.
47
+ /// </summary>
48
+ /// <param name="viewBox">The size of the view box for the QR code.</param>
49
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
50
+ /// <returns>Returns the QR code graphic as a XAML DrawingImage.</returns>
27
51
public DrawingImage GetGraphic ( Size viewBox , bool drawQuietZones = true )
28
52
=> GetGraphic ( viewBox , new SolidColorBrush ( Colors . Black ) , new SolidColorBrush ( Colors . White ) , drawQuietZones ) ;
29
53
54
+ /// <summary>
55
+ /// Returns a XAML DrawingImage that contains the resulting QR code with specified colors.
56
+ /// </summary>
57
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
58
+ /// <param name="darkColorHex">The color of the dark modules in hexadecimal format.</param>
59
+ /// <param name="lightColorHex">The color of the light modules in hexadecimal format.</param>
60
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
61
+ /// <returns>Returns the QR code graphic as a XAML DrawingImage.</returns>
30
62
public DrawingImage GetGraphic ( int pixelsPerModule , string darkColorHex , string lightColorHex , bool drawQuietZones = true )
31
63
{
32
64
var drawableModulesCount = GetDrawableModulesCount ( drawQuietZones ) ;
33
65
var viewBox = new Size ( pixelsPerModule * drawableModulesCount , pixelsPerModule * drawableModulesCount ) ;
34
66
return GetGraphic ( viewBox , new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( darkColorHex ) ) , new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( lightColorHex ) ) , drawQuietZones ) ;
35
67
}
36
68
69
+ /// <summary>
70
+ /// Returns a XAML DrawingImage that contains the resulting QR code with specified brushes.
71
+ /// </summary>
72
+ /// <param name="viewBox">The size of the view box for the QR code.</param>
73
+ /// <param name="darkBrush">The brush for the dark modules.</param>
74
+ /// <param name="lightBrush">The brush for the light modules.</param>
75
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
76
+ /// <returns>Returns the QR code graphic as a XAML DrawingImage.</returns>
37
77
public DrawingImage GetGraphic ( Size viewBox , Brush darkBrush , Brush lightBrush , bool drawQuietZones = true )
38
78
{
39
79
var drawableModulesCount = GetDrawableModulesCount ( drawQuietZones ) ;
@@ -67,6 +107,12 @@ public DrawingImage GetGraphic(Size viewBox, Brush darkBrush, Brush lightBrush,
67
107
private int GetDrawableModulesCount ( bool drawQuietZones = true )
68
108
=> QrCodeData . ModuleMatrix . Count - ( drawQuietZones ? 0 : 8 ) ;
69
109
110
+ /// <summary>
111
+ /// Calculates the number of units per module for the given view box size.
112
+ /// </summary>
113
+ /// <param name="viewBox">The size of the view box for the QR code.</param>
114
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
115
+ /// <returns>Returns the number of units per module.</returns>
70
116
public double GetUnitsPerModule ( Size viewBox , bool drawQuietZones = true )
71
117
{
72
118
var drawableModulesCount = GetDrawableModulesCount ( drawQuietZones ) ;
@@ -75,8 +121,25 @@ public double GetUnitsPerModule(Size viewBox, bool drawQuietZones = true)
75
121
}
76
122
}
77
123
124
+ /// <summary>
125
+ /// Provides static methods for creating XAML DrawingImage QR codes.
126
+ /// </summary>
78
127
public static class XamlQRCodeHelper
79
128
{
129
+ /// <summary>
130
+ /// Creates a XAML DrawingImage QR code with a single function call.
131
+ /// </summary>
132
+ /// <param name="plainText">The text or payload to be encoded inside the QR code.</param>
133
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
134
+ /// <param name="darkColorHex">The color of the dark modules in hexadecimal format.</param>
135
+ /// <param name="lightColorHex">The color of the light modules in hexadecimal format.</param>
136
+ /// <param name="eccLevel">The level of error correction data.</param>
137
+ /// <param name="forceUtf8">Specifies whether the generator should be forced to work in UTF-8 mode.</param>
138
+ /// <param name="utf8BOM">Specifies whether the byte-order-mark should be used.</param>
139
+ /// <param name="eciMode">Specifies which ECI mode should be used.</param>
140
+ /// <param name="requestedVersion">Sets the fixed QR code target version.</param>
141
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
142
+ /// <returns>Returns the QR code graphic as a XAML DrawingImage.</returns>
80
143
public static DrawingImage GetQRCode ( string plainText , int pixelsPerModule , string darkColorHex , string lightColorHex , ECCLevel eccLevel , bool forceUtf8 = false , bool utf8BOM = false , EciMode eciMode = EciMode . Default , int requestedVersion = - 1 , bool drawQuietZones = true )
81
144
{
82
145
using var qrGenerator = new QRCodeGenerator ( ) ;
0 commit comments