9
9
10
10
namespace QRCoder
11
11
{
12
+ /// <summary>
13
+ /// Represents a QR code generator that outputs base64-encoded images.
14
+ /// </summary>
12
15
public class Base64QRCode : AbstractQRCode , IDisposable
13
16
{
14
17
/// <summary>
15
- /// Constructor without params to be used in COM Objects connections
18
+ /// Initializes a new instance of the <see cref="Base64QRCode"/> class.
19
+ /// Constructor without parameters to be used in COM objects connections.
16
20
/// </summary>
17
21
public Base64QRCode ( ) {
18
22
}
19
23
24
+ /// <summary>
25
+ /// Initializes a new instance of the <see cref="Base64QRCode"/> class with the specified <see cref="QRCodeData"/>.
26
+ /// </summary>
27
+ /// <param name="data"><see cref="QRCodeData"/> generated by the QRCodeGenerator.</param>
20
28
public Base64QRCode ( QRCodeData data ) : base ( data ) {
21
29
}
22
30
31
+ /// <summary>
32
+ /// Returns a base64-encoded string that contains the resulting QR code as a PNG image.
33
+ /// </summary>
34
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
35
+ /// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
23
36
public string GetGraphic ( int pixelsPerModule )
24
37
{
25
38
return this . GetGraphic ( pixelsPerModule , Color . Black , Color . White , true ) ;
26
39
}
27
40
28
-
41
+ /// <summary>
42
+ /// Returns a base64-encoded string that contains the resulting QR code as an image.
43
+ /// </summary>
44
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
45
+ /// <param name="darkColorHtmlHex">The color of the dark modules in HTML hex format.</param>
46
+ /// <param name="lightColorHtmlHex">The color of the light modules in HTML hex format.</param>
47
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
48
+ /// <param name="imgType">The type of image to generate (PNG, JPEG, GIF).</param>
49
+ /// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
29
50
public string GetGraphic ( int pixelsPerModule , string darkColorHtmlHex , string lightColorHtmlHex , bool drawQuietZones = true , ImageType imgType = ImageType . Png )
30
51
{
31
52
return this . GetGraphic ( pixelsPerModule , ColorTranslator . FromHtml ( darkColorHtmlHex ) , ColorTranslator . FromHtml ( lightColorHtmlHex ) , drawQuietZones , imgType ) ;
32
53
}
33
54
55
+ /// <summary>
56
+ /// Returns a base64-encoded string that contains the resulting QR code as an image.
57
+ /// </summary>
58
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
59
+ /// <param name="darkColor">The color of the dark modules.</param>
60
+ /// <param name="lightColor">The color of the light modules.</param>
61
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
62
+ /// <param name="imgType">The type of image to generate (PNG, JPEG, GIF).</param>
63
+ /// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
34
64
public string GetGraphic ( int pixelsPerModule , Color darkColor , Color lightColor , bool drawQuietZones = true , ImageType imgType = ImageType . Png )
35
65
{
36
66
if ( imgType == ImageType . Png )
@@ -78,6 +108,18 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
78
108
}
79
109
80
110
#if SYSTEM_DRAWING
111
+ /// <summary>
112
+ /// Returns a base64-encoded string that contains the resulting QR code as an image with an embedded icon.
113
+ /// </summary>
114
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
115
+ /// <param name="darkColor">The color of the dark modules.</param>
116
+ /// <param name="lightColor">The color of the light modules.</param>
117
+ /// <param name="icon">The icon to embed in the center of the QR code.</param>
118
+ /// <param name="iconSizePercent">The size of the icon as a percentage of the QR code.</param>
119
+ /// <param name="iconBorderWidth">The width of the border around the icon.</param>
120
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
121
+ /// <param name="imgType">The type of image to generate (PNG, JPEG, GIF).</param>
122
+ /// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
81
123
#if NET6_0_OR_GREATER
82
124
[ System . Runtime . Versioning . SupportedOSPlatform ( "windows" ) ]
83
125
#endif
@@ -94,6 +136,12 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
94
136
#endif
95
137
96
138
#if SYSTEM_DRAWING
139
+ /// <summary>
140
+ /// Converts a bitmap to a base64-encoded string.
141
+ /// </summary>
142
+ /// <param name="bmp">The bitmap to convert.</param>
143
+ /// <param name="imgType">The type of image (PNG, JPEG, GIF).</param>
144
+ /// <returns>Returns the base64-encoded string representation of the bitmap.</returns>
97
145
#if NET6_0_OR_GREATER
98
146
[ System . Runtime . Versioning . SupportedOSPlatform ( "windows" ) ]
99
147
#endif
@@ -124,23 +172,53 @@ private string BitmapToBase64(Bitmap bmp, ImageType imgType)
124
172
}
125
173
#endif
126
174
175
+ /// <summary>
176
+ /// Specifies the type of image to generate.
177
+ /// </summary>
127
178
public enum ImageType
128
179
{
129
180
#if NET6_0_OR_GREATER
130
181
[ System . Runtime . Versioning . SupportedOSPlatform ( "windows" ) ]
131
182
#endif
183
+ /// <summary>
184
+ /// GIF image format.
185
+ /// </summary>
132
186
Gif ,
133
187
#if NET6_0_OR_GREATER
134
188
[ System . Runtime . Versioning . SupportedOSPlatform ( "windows" ) ]
135
189
#endif
190
+ /// <summary>
191
+ /// JPEG image format.
192
+ /// </summary>
136
193
Jpeg ,
194
+ /// <summary>
195
+ /// PNG image format.
196
+ /// </summary>
137
197
Png
138
198
}
139
199
140
200
}
141
201
202
+ /// <summary>
203
+ /// Provides static methods for creating base64-encoded QR codes.
204
+ /// </summary>
142
205
public static class Base64QRCodeHelper
143
206
{
207
+ /// <summary>
208
+ /// Creates a base64-encoded QR code with a single function call.
209
+ /// </summary>
210
+ /// <param name="plainText">The text or payload to be encoded inside the QR code.</param>
211
+ /// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
212
+ /// <param name="darkColorHtmlHex">The color of the dark modules in HTML hex format.</param>
213
+ /// <param name="lightColorHtmlHex">The color of the light modules in HTML hex format.</param>
214
+ /// <param name="eccLevel">The level of error correction data.</param>
215
+ /// <param name="forceUtf8">Specifies whether the generator should be forced to work in UTF-8 mode.</param>
216
+ /// <param name="utf8BOM">Specifies whether the byte-order-mark should be used.</param>
217
+ /// <param name="eciMode">Specifies which ECI mode should be used.</param>
218
+ /// <param name="requestedVersion">Sets the fixed QR code target version.</param>
219
+ /// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
220
+ /// <param name="imgType">The type of image to generate (PNG, JPEG, GIF).</param>
221
+ /// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
144
222
public static string GetQRCode ( string plainText , int pixelsPerModule , string darkColorHtmlHex , string lightColorHtmlHex , ECCLevel eccLevel , bool forceUtf8 = false , bool utf8BOM = false , EciMode eciMode = EciMode . Default , int requestedVersion = - 1 , bool drawQuietZones = true , ImageType imgType = ImageType . Png )
145
223
{
146
224
using ( var qrGenerator = new QRCodeGenerator ( ) )
@@ -151,4 +229,4 @@ public static string GetQRCode(string plainText, int pixelsPerModule, string dar
151
229
}
152
230
}
153
231
154
- #endif
232
+ #endif
0 commit comments