private void grpBoxQRCode_Resize(object sender, EventArgs e) { var margin = 15; int squareSize = Math.Min(grpBoxQRCode.Width - margin * 2, grpBoxQRCode.Height - margin * 2); PicBoxQRCode.SetBounds(margin, margin, squareSize, squareSize); PicBoxQRCode.Width = squareSize; PicBoxQRCode.Left = (grpBoxQRCode.Width - PicBoxQRCode.Width) / 2; }
private async Task GenerateQrCode() { await Task.Run(() => { var qrCodeGenerator = new QRCodeGenerator(); string enValue = _activeSettings.QR_CodeLevel.ToString(); var ecc = (QRCodeGenerator.ECCLevel)Enum.Parse(typeof(QRCodeGenerator.ECCLevel), enValue); string encoderContent = CreateWifiMetadataFormatString(txtSSId.Text, rdWPA.Checked, txtGeneratedPassword.Text, rdSSIDVisibleFalse.Checked); var qrCode = qrCodeGenerator.CreateQrCode(encoderContent, ecc); int moduleCount = qrCode.ModuleMatrix.Count; PicBoxQRCode.Image = _qrOutputSize == Size.Empty ? qrCode.GetGraphic(Math.Max(500, PicBoxQRCode.Height) / moduleCount) : qrCode.GetGraphic(_qrOutputSize.Height / moduleCount); }); PicBoxQRCode.Refresh(); PicBoxQRCode.BorderStyle = BorderStyle.None; PicBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage; }
private async Task GnerateQrCode() { PicBoxQRCode.SuspendLayout(); Image qrCodeImg = null; await Task.Run(() => { var qrCodeGenerator = new QRCodeGenerator(); string enValue = _activeSettings.QR_CodeLevel.ToString(); var ecc = (QRCodeGenerator.ECCLevel)Enum.Parse(typeof(QRCodeGenerator.ECCLevel), enValue); string encoderContent = CreateWifimetadataFormatString(txtSSId.Text, rdWPA.Checked, txtGeneratedPassword.Text, rdSSIDVisibleFalse.Checked); var qrCode = qrCodeGenerator.CreateQrCode(encoderContent, ecc); int moduleCount = qrCode.ModuleMatrix.Count; int optimalPixelsPerMatrixModule = moduleCount; if (_qrOutputSize == null) { _qrOutputSize = new Size(_activeSettings.ImageWidth, _activeSettings.ImageWidth); } else if (_qrOutputSize.Width < _activeSettings.ImageWidth || _qrOutputSize.Height < _activeSettings.ImageWidth) { _qrOutputSize = new Size(_activeSettings.ImageWidth, _activeSettings.ImageWidth); } double pixelsDelta = _qrOutputSize.Width; optimalPixelsPerMatrixModule = Convert.ToInt32(Math.Ceiling(pixelsDelta / Convert.ToDouble(moduleCount))); qrCodeImg = qrCode.CreateBitmap(optimalPixelsPerMatrixModule); }); PicBoxQRCode.Image = qrCodeImg; PicBoxQRCode.ResumeLayout(); PicBoxQRCode.Refresh(); PicBoxQRCode.BorderStyle = BorderStyle.FixedSingle; PicBoxQRCode.SizeMode = PictureBoxSizeMode.Zoom; }