Skip to content

Commit 34beea6

Browse files
authored
Merge pull request #273 from hong4rc/patch-1
Simple demo
2 parents 49d5b35 + c150b22 commit 34beea6

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

QRCoderDemo/Form1.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,34 @@ private void RenderQrCode()
3535
string level = comboBoxECC.SelectedItem.ToString();
3636
QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3);
3737
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
38+
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(textBoxQRCode.Text, eccLevel))
39+
using (QRCode qrCode = new QRCode(qrCodeData))
3840
{
39-
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(textBoxQRCode.Text, eccLevel))
40-
{
41-
using (QRCode qrCode = new QRCode(qrCodeData))
42-
{
43-
pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(20, GetPrimaryColor(), GetBackgroundColor(),
44-
GetIconBitmap(), (int) iconSize.Value);
41+
pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(20, GetPrimaryColor(), GetBackgroundColor(),
42+
GetIconBitmap(), (int)iconSize.Value);
4543

46-
this.pictureBoxQRCode.Size = new System.Drawing.Size(pictureBoxQRCode.Width, pictureBoxQRCode.Height);
47-
//Set the SizeMode to center the image.
48-
this.pictureBoxQRCode.SizeMode = PictureBoxSizeMode.CenterImage;
44+
this.pictureBoxQRCode.Size = new System.Drawing.Size(pictureBoxQRCode.Width, pictureBoxQRCode.Height);
45+
//Set the SizeMode to center the image.
46+
this.pictureBoxQRCode.SizeMode = PictureBoxSizeMode.CenterImage;
4947

50-
pictureBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage;
51-
}
52-
}
48+
pictureBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage;
5349
}
5450
}
5551

5652
private Bitmap GetIconBitmap()
5753
{
58-
Bitmap img = null;
59-
if (iconPath.Text.Length > 0)
54+
if (iconPath.Text.Length == 0)
6055
{
61-
try
62-
{
63-
img = new Bitmap(iconPath.Text);
64-
}
65-
catch (Exception)
66-
{
67-
}
56+
return null;
57+
}
58+
try
59+
{
60+
return new Bitmap(iconPath.Text);
61+
}
62+
catch (Exception)
63+
{
64+
return null;
6865
}
69-
return img;
7066
}
7167

7268
private void selectIconBtn_Click(object sender, EventArgs e)

0 commit comments

Comments
 (0)