@@ -19,7 +19,7 @@ public class QRCodeRendererTests
19
19
#if ! NETCOREAPP1_1
20
20
[ Fact ]
21
21
[ Category ( "QRRenderer/QRCode" ) ]
22
- public void can_create_standard_qrcode_graphic ( )
22
+ public void can_create_qrcode_standard_graphic ( )
23
23
{
24
24
var gen = new QRCodeGenerator ( ) ;
25
25
var data = gen . CreateQrCode ( "This is a quick test! 123#?" , QRCodeGenerator . ECCLevel . H ) ;
@@ -28,10 +28,36 @@ public void can_create_standard_qrcode_graphic()
28
28
var result = HelperFunctions . BitmapToHash ( bmp ) ;
29
29
result . ShouldBe ( "e8c61b8f0455924fe08ba68686d0d296" ) ;
30
30
}
31
- #endif
32
31
32
+ [ Fact ]
33
+ [ Category ( "QRRenderer/QRCode" ) ]
34
+ public void can_create_qrcode_standard_graphic_hex ( )
35
+ {
36
+ var gen = new QRCodeGenerator ( ) ;
37
+ var data = gen . CreateQrCode ( "This is a quick test! 123#?" , QRCodeGenerator . ECCLevel . H ) ;
38
+ var bmp = new QRCode ( data ) . GetGraphic ( 10 , "#000000" , "#ffffff" ) ;
39
+
40
+ var result = HelperFunctions . BitmapToHash ( bmp ) ;
41
+ result . ShouldBe ( "e8c61b8f0455924fe08ba68686d0d296" ) ;
42
+ }
43
+
44
+
45
+ [ Fact ]
46
+ [ Category ( "QRRenderer/QRCode" ) ]
47
+ public void can_create_qrcode_standard_graphic_without_quietzones ( )
48
+ {
49
+ var gen = new QRCodeGenerator ( ) ;
50
+ var data = gen . CreateQrCode ( "This is a quick test! 123#?" , QRCodeGenerator . ECCLevel . H ) ;
51
+ var bmp = new QRCode ( data ) . GetGraphic ( 5 , Color . Black , Color . White , false ) ;
52
+
53
+ var result = HelperFunctions . BitmapToHash ( bmp ) ;
54
+ #if NET35_OR_GREATER || NET40_OR_GREATER
55
+ result . ShouldBe ( "329e1664f57cbe7332d8d4db04c1d480" ) ;
56
+ #else
57
+ result . ShouldBe ( "d703e54a0ba541c6ea69e3d316e394e7" ) ;
58
+ #endif
59
+ }
33
60
34
- #if ! NETCOREAPP1_1 && ! NETCOREAPP2_0
35
61
36
62
[ Fact ]
37
63
[ Category ( "QRRenderer/QRCode" ) ]
@@ -43,7 +69,6 @@ public void can_create_qrcode_with_transparent_logo_graphic()
43
69
44
70
var bmp = new QRCode ( data ) . GetGraphic ( 10 , Color . Black , Color . Transparent , icon : ( Bitmap ) Image . FromFile ( HelperFunctions . GetAssemblyPath ( ) + "\\ assets\\ noun_software engineer_2909346.png" ) ) ;
45
71
//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
46
-
47
72
var result = HelperFunctions . BitmapToHash ( bmp ) ;
48
73
#if NET35_OR_GREATER || NET40_OR_GREATER
49
74
result . ShouldBe ( "ee65d96c3013f6032b561cc768251eef" ) ;
@@ -70,28 +95,83 @@ public void can_create_qrcode_with_non_transparent_logo_graphic()
70
95
#endif
71
96
}
72
97
73
- /*
74
- private static byte[] PixelsToAveragedByteArray(Bitmap bmp)
98
+ [ Fact ]
99
+ [ Category ( "QRRenderer/QRCode" ) ]
100
+ public void can_create_qrcode_with_logo_and_with_transparent_border ( )
101
+ {
102
+ //Create QR code
103
+ var gen = new QRCodeGenerator ( ) ;
104
+ var data = gen . CreateQrCode ( "This is a quick test! 123#?" , QRCodeGenerator . ECCLevel . H ) ;
105
+
106
+ var logo = ( Bitmap ) Image . FromFile ( HelperFunctions . GetAssemblyPath ( ) + "\\ assets\\ noun_software engineer_2909346.png" ) ;
107
+ var bmp = new QRCode ( data ) . GetGraphic ( 10 , Color . Black , Color . Transparent , icon : logo , iconBorderWidth : 6 ) ;
108
+ //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
109
+ var result = HelperFunctions . BitmapToHash ( bmp ) ;
110
+ #if NET35_OR_GREATER || NET40_OR_GREATER
111
+ result . ShouldBe ( "ee65d96c3013f6032b561cc768251eef" ) ;
112
+ #else
113
+ result . ShouldBe ( "150f8fc7dae4487ba2887d2b2bea1c25" ) ;
114
+ #endif
115
+ }
116
+
117
+ [ Fact ]
118
+ [ Category ( "QRRenderer/QRCode" ) ]
119
+ public void can_create_qrcode_with_logo_and_with_standard_border ( )
120
+ {
121
+ //Create QR code
122
+ var gen = new QRCodeGenerator ( ) ;
123
+ var data = gen . CreateQrCode ( "This is a quick test! 123#?" , QRCodeGenerator . ECCLevel . H ) ;
124
+
125
+ var logo = ( Bitmap ) Image . FromFile ( HelperFunctions . GetAssemblyPath ( ) + "\\ assets\\ noun_software engineer_2909346.png" ) ;
126
+ var bmp = new QRCode ( data ) . GetGraphic ( 10 , Color . Black , Color . White , icon : logo , iconBorderWidth : 6 ) ;
127
+ //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
128
+ var result = HelperFunctions . BitmapToHash ( bmp ) ;
129
+ #if NET35_OR_GREATER || NET40_OR_GREATER
130
+ result . ShouldBe ( "52207bd86ca5a532fb2095dbaa0ae04c" ) ;
131
+ #else
132
+ result . ShouldBe ( "1c926ea1d48f42fdf8e6f1438b774cdd" ) ;
133
+ #endif
134
+ }
135
+
136
+ [ Fact ]
137
+ [ Category ( "QRRenderer/QRCode" ) ]
138
+ public void can_create_qrcode_with_logo_and_with_custom_border ( )
75
139
{
76
- //Re-color
77
- var bmpTmp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
78
- using (var gr = Graphics.FromImage(bmp))
79
- gr.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
80
-
81
- //Downscale
82
- var bmpSmall = new Bitmap(bmpTmp, new Size(16, 16));
83
-
84
- var bytes = new System.Collections.Generic.List<byte>();
85
- for (int x = 0; x < bmpSmall.Width; x++)
86
- {
87
- for (int y = 0; y < bmpSmall.Height; y++)
88
- {
89
- bytes.AddRange(new byte[] { bmpSmall.GetPixel(x, y).R, bmpSmall.GetPixel(x, y).G, bmpSmall.GetPixel(x, y).B });
90
- }
91
- }
92
- return bytes.ToArray();
140
+ //Create QR code
141
+ var gen = new QRCodeGenerator ( ) ;
142
+ var data = gen . CreateQrCode ( "This is a quick test! 123#?" , QRCodeGenerator . ECCLevel . H ) ;
143
+
144
+ var logo = ( Bitmap ) Image . FromFile ( HelperFunctions . GetAssemblyPath ( ) + "\\ assets\\ noun_software engineer_2909346.png" ) ;
145
+ var bmp = new QRCode ( data ) . GetGraphic ( 10 , Color . Black , Color . Transparent , icon : logo , iconBorderWidth : 6 , iconBackgroundColor : Color . DarkGreen ) ;
146
+ //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
147
+ var result = HelperFunctions . BitmapToHash ( bmp ) ;
148
+ #if NET35_OR_GREATER || NET40_OR_GREATER
149
+ result . ShouldBe ( "d2f20d34a973d92b9c3e05db1393b331" ) ;
150
+ #else
151
+ result . ShouldBe ( "9a06bfbb72df999b6290b5af5c4037cb" ) ;
152
+ #endif
153
+ }
154
+
155
+
156
+ [ Fact ]
157
+ [ Category ( "QRRenderer/QRCode" ) ]
158
+ public void can_instantate_qrcode_parameterless ( )
159
+ {
160
+ var svgCode = new QRCode ( ) ;
161
+ svgCode . ShouldNotBeNull ( ) ;
162
+ svgCode . ShouldBeOfType < QRCode > ( ) ;
163
+ }
164
+
165
+ [ Fact ]
166
+ [ Category ( "QRRenderer/QRCode" ) ]
167
+ public void can_render_qrcode_from_helper ( )
168
+ {
169
+ //Create QR code
170
+ var bmp = QRCodeHelper . GetQRCode ( "This is a quick test! 123#?" , 10 , Color . Black , Color . White , QRCodeGenerator . ECCLevel . H ) ;
171
+
172
+ var result = HelperFunctions . BitmapToHash ( bmp ) ;
173
+ result . ShouldBe ( "e8c61b8f0455924fe08ba68686d0d296" ) ;
93
174
}
94
- */
95
175
#endif
96
176
}
97
177
}
0 commit comments