4
4
using System . Drawing ;
5
5
using System . Drawing . Drawing2D ;
6
6
7
+ // pull request raised to extend library used.
7
8
namespace QRCoder
8
9
{
9
10
public class LogoQRCode : AbstractQRCode , IDisposable
@@ -15,17 +16,25 @@ public LogoQRCode() { }
15
16
16
17
public LogoQRCode ( QRCodeData data ) : base ( data ) { }
17
18
18
- public Bitmap GetGraphic ( QRCodeData qrCodeData ,
19
- int pixelsPerModule ,
19
+ public Bitmap GetGraphic ( Bitmap backgroundImage = null )
20
+ {
21
+ return this . GetGraphic ( 10 , 7 , Color . Black , Color . White , backgroundImage : backgroundImage ) ;
22
+ }
23
+
24
+ public Bitmap GetGraphic ( int pixelsPerModule , Bitmap backgroundImage = null )
25
+ {
26
+ return this . GetGraphic ( pixelsPerModule , ( pixelsPerModule * 8 ) / 10 , Color . Black , Color . White , backgroundImage : backgroundImage ) ;
27
+ }
28
+
29
+ public Bitmap GetGraphic ( int pixelsPerModule ,
20
30
int pixelSize ,
21
31
Color darkColor ,
22
32
Color lightColor ,
33
+ Bitmap backgroundImage = null ,
23
34
bool drawQuietZones = false ,
24
- Bitmap reticalImage = null ,
25
- Base64QRCode . ImageType imgType = Base64QRCode . ImageType . Png ,
26
- Bitmap backgroundImage = null )
35
+ Bitmap reticleImage = null )
27
36
{
28
- int numModules = qrCodeData . ModuleMatrix . Count - ( drawQuietZones ? 0 : 8 ) ;
37
+ int numModules = this . QrCodeData . ModuleMatrix . Count - ( drawQuietZones ? 0 : 8 ) ;
29
38
var offset = ( drawQuietZones ? 0 : 4 ) ;
30
39
int size = numModules * pixelsPerModule ;
31
40
var moduleMargin = pixelsPerModule - pixelSize ;
@@ -52,22 +61,26 @@ public Bitmap GetGraphic(QRCodeData qrCodeData,
52
61
{
53
62
for ( int y = 0 ; y < numModules ; y += 1 )
54
63
{
55
- var solidBrush = ( System . Drawing . Brush ) ( qrCodeData . ModuleMatrix [ offset + y ] [ offset + x ] ? darkBrush : lightBrush ) ;
64
+ var solidBrush = ( Brush ) ( this . QrCodeData . ModuleMatrix [ offset + y ] [ offset + x ] ? darkBrush : lightBrush ) ;
56
65
57
- if ( IsPartOfRetical ( x , y , numModules , offset ) )
58
- if ( reticalImage == null )
66
+ if ( IsPartOfReticle ( x , y , numModules , offset ) )
67
+ {
68
+ if ( reticleImage == null )
69
+ {
59
70
graphics . FillRectangle ( solidBrush , new Rectangle ( x * pixelsPerModule , y * pixelsPerModule , pixelsPerModule , pixelsPerModule ) ) ;
60
- else
61
- graphics . FillEllipse ( solidBrush , new Rectangle ( x * pixelsPerModule + moduleMargin , y * pixelsPerModule + moduleMargin , pixelSize , pixelSize ) ) ;
71
+ }
72
+ }
73
+ else
74
+ graphics . FillEllipse ( solidBrush , new Rectangle ( x * pixelsPerModule + moduleMargin , y * pixelsPerModule + moduleMargin , pixelSize , pixelSize ) ) ;
62
75
}
63
76
}
64
77
65
- if ( reticalImage != null )
78
+ if ( reticleImage != null )
66
79
{
67
80
var reticleSize = 7 * pixelsPerModule ;
68
- graphics . DrawImage ( reticalImage , new Rectangle ( 0 , 0 , reticleSize , reticleSize ) ) ;
69
- graphics . DrawImage ( reticalImage , new Rectangle ( size - reticleSize , 0 , reticleSize , reticleSize ) ) ;
70
- graphics . DrawImage ( reticalImage , new Rectangle ( 0 , size - reticleSize , reticleSize , reticleSize ) ) ;
81
+ graphics . DrawImage ( reticleImage , new Rectangle ( 0 , 0 , reticleSize , reticleSize ) ) ;
82
+ graphics . DrawImage ( reticleImage , new Rectangle ( size - reticleSize , 0 , reticleSize , reticleSize ) ) ;
83
+ graphics . DrawImage ( reticleImage , new Rectangle ( 0 , size - reticleSize , reticleSize , reticleSize ) ) ;
71
84
}
72
85
73
86
graphics . Save ( ) ;
@@ -77,13 +90,13 @@ public Bitmap GetGraphic(QRCodeData qrCodeData,
77
90
return bitmap ;
78
91
}
79
92
80
- private bool IsPartOfRetical ( int x , int y , int numModules , int offset )
93
+ private bool IsPartOfReticle ( int x , int y , int numModules , int offset )
81
94
{
82
- var cornerSize = 7 + offset ;
95
+ var cornerSize = 11 - offset ;
83
96
return
84
97
( x < cornerSize && y < cornerSize ) ||
85
- ( x > ( numModules - cornerSize ) && y < cornerSize ) ||
86
- ( x < cornerSize && y < ( numModules - cornerSize ) ) ;
98
+ ( x > ( numModules - cornerSize - 1 ) && y < cornerSize ) ||
99
+ ( x < cornerSize && y > ( numModules - cornerSize - 1 ) ) ;
87
100
}
88
101
89
102
private Bitmap Resize ( Bitmap image , int size )
0 commit comments