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)) {