Make sure QR code output is square image

This commit is contained in:
Jaex 2018-02-26 09:47:34 +03:00
parent 36b0609dd9
commit 749d52e484
4 changed files with 18 additions and 9 deletions

View file

@ -33,6 +33,7 @@ private void InitializeComponent()
this.cmsQR = new System.Windows.Forms.ContextMenuStrip(this.components);
this.tsmiCopy = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiSaveAs = new System.Windows.Forms.ToolStripMenuItem();
this.tsmiDecode = new System.Windows.Forms.ToolStripMenuItem();
this.txtQRCode = new System.Windows.Forms.TextBox();
this.pbQRCode = new System.Windows.Forms.PictureBox();
this.tcMain = new System.Windows.Forms.TabControl();
@ -42,7 +43,6 @@ private void InitializeComponent()
this.txtDecodeResult = new System.Windows.Forms.TextBox();
this.lblDecodeResult = new System.Windows.Forms.Label();
this.btnDecodeFromScreen = new System.Windows.Forms.Button();
this.tsmiDecode = new System.Windows.Forms.ToolStripMenuItem();
this.cmsQR.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbQRCode)).BeginInit();
this.tcMain.SuspendLayout();
@ -72,6 +72,12 @@ private void InitializeComponent()
resources.ApplyResources(this.tsmiSaveAs, "tsmiSaveAs");
this.tsmiSaveAs.Click += new System.EventHandler(this.tsmiSaveAs_Click);
//
// tsmiDecode
//
this.tsmiDecode.Name = "tsmiDecode";
resources.ApplyResources(this.tsmiDecode, "tsmiDecode");
this.tsmiDecode.Click += new System.EventHandler(this.tsmiDecode_Click);
//
// txtQRCode
//
resources.ApplyResources(this.txtQRCode, "txtQRCode");
@ -136,12 +142,6 @@ private void InitializeComponent()
this.btnDecodeFromScreen.UseVisualStyleBackColor = true;
this.btnDecodeFromScreen.Click += new System.EventHandler(this.btnDecodeFromScreen_Click);
//
// tsmiDecode
//
this.tsmiDecode.Name = "tsmiDecode";
resources.ApplyResources(this.tsmiDecode, "tsmiDecode");
this.tsmiDecode.Click += new System.EventHandler(this.tsmiDecode_Click);
//
// QRCodeForm
//
resources.ApplyResources(this, "$this");

View file

@ -91,7 +91,8 @@ private void EncodeText(string text)
{
ClearQRCode();
pbQRCode.Image = TaskHelpers.QRCodeEncode(text, pbQRCode.Width, pbQRCode.Height);
int size = Math.Min(pbQRCode.Width, pbQRCode.Height);
pbQRCode.Image = TaskHelpers.QRCodeEncode(text, size);
}
}

View file

@ -140,7 +140,7 @@
<value>Decode</value>
</data>
<data name="cmsQR.Size" type="System.Drawing.Size, System.Drawing">
<value>152, 92</value>
<value>152, 70</value>
</data>
<data name="cmsQR.Text" xml:space="preserve">
<value>QR</value>
@ -186,6 +186,9 @@
<data name="pbQRCode.Size" type="System.Drawing.Size, System.Drawing">
<value>460, 444</value>
</data>
<data name="pbQRCode.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
<value>CenterImage</value>
</data>
<data name="pbQRCode.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>

View file

@ -1602,6 +1602,11 @@ public static Image QRCodeEncode(string text, int width, int height)
return null;
}
public static Image QRCodeEncode(string text, int size)
{
return QRCodeEncode(text, size, size);
}
public static string[] QRCodeDecode(Bitmap bmp)
{
try