Skip to content

Commit 0853545

Browse files
committed
cleanup
1 parent 91839cf commit 0853545

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

QRCoder/ArtQRCode.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@ public Bitmap GetGraphic(
3535
Bitmap reticleImage = null,
3636
Bitmap backgroundImage = null)
3737
{
38-
int numModules = this.QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8);
38+
var numModules = this.QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8);
3939
var offset = (drawQuietZones ? 0 : 4);
40-
int size = numModules * pixelsPerModule;
41-
var moduleMargin = pixelsPerModule - pixelSize;
40+
var size = numModules * pixelsPerModule;
4241

43-
Bitmap bitmap = backgroundImage ?? new Bitmap(size, size);
44-
bitmap = Resize(bitmap, size);
42+
var bitmap = Resize(backgroundImage,size) ?? new Bitmap(size, size);
4543

46-
47-
using (Graphics graphics = Graphics.FromImage(bitmap))
44+
using (var graphics = Graphics.FromImage(bitmap))
4845
{
49-
using (SolidBrush lightBrush = new SolidBrush(lightColor))
46+
using (var lightBrush = new SolidBrush(lightColor))
5047
{
51-
using (SolidBrush darkBrush = new SolidBrush(darkColor))
48+
using (var darkBrush = new SolidBrush(darkColor))
5249
{
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
5451
if (backgroundImage == null)
5552
{
5653
using (var brush = new SolidBrush(Color.Transparent))
@@ -62,9 +59,9 @@ public Bitmap GetGraphic(
6259
var darkModulePixel = MakeDotPixel(pixelsPerModule, pixelSize, darkBrush);
6360
var lightModulePixel = MakeDotPixel(pixelsPerModule, pixelSize, lightBrush);
6461

65-
for (int x = 0; x < numModules; x += 1)
62+
for (var x = 0; x < numModules; x += 1)
6663
{
67-
for (int y = 0; y < numModules; y += 1)
64+
for (var y = 0; y < numModules; y += 1)
6865
{
6966
var rectangleF = new Rectangle(x * pixelsPerModule, y * pixelsPerModule, pixelsPerModule, pixelsPerModule);
7067

@@ -145,6 +142,8 @@ private bool IsPartOfReticle(int x, int y, int numModules, int offset)
145142
/// <returns></returns>
146143
private Bitmap Resize(Bitmap image, int newSize)
147144
{
145+
if (image == null) return null;
146+
148147
float scale = Math.Min((float)newSize / image.Width, (float)newSize / image.Height);
149148
var scaledWidth = (int)(image.Width * scale);
150149
var scaledHeight = (int)(image.Height * scale);

0 commit comments

Comments
 (0)