From a447feece2e2c9d89a0e40665d07eecbce814fc9 Mon Sep 17 00:00:00 2001 From: noisyfox Date: Tue, 13 Dec 2016 20:43:51 +1100 Subject: [PATCH] Adjust qrcode display --- shadowsocks-csharp/View/QRCodeForm.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shadowsocks-csharp/View/QRCodeForm.cs b/shadowsocks-csharp/View/QRCodeForm.cs index eb009cbf..4537e0f1 100755 --- a/shadowsocks-csharp/View/QRCodeForm.cs +++ b/shadowsocks-csharp/View/QRCodeForm.cs @@ -33,6 +33,14 @@ namespace Shadowsocks.View QRCode code = ZXing.QrCode.Internal.Encoder.encode(qrText, ErrorCorrectionLevel.M); ByteMatrix m = code.Matrix; int blockSize = Math.Max(pictureBox1.Height/m.Height, 1); + + var qrWidth = m.Width*blockSize; + var qrHeight = m.Height*blockSize; + var dWidth = pictureBox1.Width - qrWidth; + var dHeight = pictureBox1.Height - qrHeight; + var maxD = Math.Max(dWidth, dHeight); + pictureBox1.SizeMode = maxD >= 7*blockSize ? PictureBoxSizeMode.Zoom : PictureBoxSizeMode.CenterImage; + Bitmap drawArea = new Bitmap((m.Width*blockSize), (m.Height*blockSize)); using (Graphics g = Graphics.FromImage(drawArea)) {