@@ -35,22 +35,19 @@ public Bitmap GetGraphic(
35
35
Bitmap reticleImage = null ,
36
36
Bitmap backgroundImage = null )
37
37
{
38
- int numModules = this . QrCodeData . ModuleMatrix . Count - ( drawQuietZones ? 0 : 8 ) ;
38
+ var numModules = this . QrCodeData . ModuleMatrix . Count - ( drawQuietZones ? 0 : 8 ) ;
39
39
var offset = ( drawQuietZones ? 0 : 4 ) ;
40
- int size = numModules * pixelsPerModule ;
41
- var moduleMargin = pixelsPerModule - pixelSize ;
40
+ var size = numModules * pixelsPerModule ;
42
41
43
- Bitmap bitmap = backgroundImage ?? new Bitmap ( size , size ) ;
44
- bitmap = Resize ( bitmap , size ) ;
42
+ var bitmap = Resize ( backgroundImage , size ) ?? new Bitmap ( size , size ) ;
45
43
46
-
47
- using ( Graphics graphics = Graphics . FromImage ( bitmap ) )
44
+ using ( var graphics = Graphics . FromImage ( bitmap ) )
48
45
{
49
- using ( SolidBrush lightBrush = new SolidBrush ( lightColor ) )
46
+ using ( var lightBrush = new SolidBrush ( lightColor ) )
50
47
{
51
- using ( SolidBrush darkBrush = new SolidBrush ( darkColor ) )
48
+ using ( var darkBrush = new SolidBrush ( darkColor ) )
52
49
{
53
- // make background transparent if you don't have an image
50
+ // make background transparent if you don't have an image -- not sure this is needed
54
51
if ( backgroundImage == null )
55
52
{
56
53
using ( var brush = new SolidBrush ( Color . Transparent ) )
@@ -62,9 +59,9 @@ public Bitmap GetGraphic(
62
59
var darkModulePixel = MakeDotPixel ( pixelsPerModule , pixelSize , darkBrush ) ;
63
60
var lightModulePixel = MakeDotPixel ( pixelsPerModule , pixelSize , lightBrush ) ;
64
61
65
- for ( int x = 0 ; x < numModules ; x += 1 )
62
+ for ( var x = 0 ; x < numModules ; x += 1 )
66
63
{
67
- for ( int y = 0 ; y < numModules ; y += 1 )
64
+ for ( var y = 0 ; y < numModules ; y += 1 )
68
65
{
69
66
var rectangleF = new Rectangle ( x * pixelsPerModule , y * pixelsPerModule , pixelsPerModule , pixelsPerModule ) ;
70
67
@@ -145,6 +142,8 @@ private bool IsPartOfReticle(int x, int y, int numModules, int offset)
145
142
/// <returns></returns>
146
143
private Bitmap Resize ( Bitmap image , int newSize )
147
144
{
145
+ if ( image == null ) return null ;
146
+
148
147
float scale = Math . Min ( ( float ) newSize / image . Width , ( float ) newSize / image . Height ) ;
149
148
var scaledWidth = ( int ) ( image . Width * scale ) ;
150
149
var scaledHeight = ( int ) ( image . Height * scale ) ;
0 commit comments