Added QR code size option

This commit is contained in:
Jaex 2023-06-13 09:57:36 +03:00
parent bf75db0e74
commit c2480351b8
4 changed files with 194 additions and 62 deletions

View file

@ -37,19 +37,22 @@ private void InitializeComponent()
this.tss1 = new System.Windows.Forms.ToolStripSeparator();
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();
this.tpEncode = new System.Windows.Forms.TabPage();
this.nudQRCodeSize = new System.Windows.Forms.NumericUpDown();
this.tpDecode = new System.Windows.Forms.TabPage();
this.pDecodeResult = new System.Windows.Forms.Panel();
this.rtbDecodeResult = new System.Windows.Forms.RichTextBox();
this.btnDecodeFromFile = new System.Windows.Forms.Button();
this.lblDecodeResult = new System.Windows.Forms.Label();
this.btnDecodeFromScreen = new System.Windows.Forms.Button();
this.rtbDecodeResult = new System.Windows.Forms.RichTextBox();
this.pDecodeResult = new System.Windows.Forms.Panel();
this.pbQRCode = new ShareX.HelpersLib.MyPictureBox();
this.lblQRCodeSize = new System.Windows.Forms.Label();
this.lblQRCodeSizeHint = new System.Windows.Forms.Label();
this.cmsQR.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbQRCode)).BeginInit();
this.tcMain.SuspendLayout();
this.tpEncode.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudQRCodeSize)).BeginInit();
this.tpDecode.SuspendLayout();
this.pDecodeResult.SuspendLayout();
this.SuspendLayout();
@ -102,13 +105,6 @@ private void InitializeComponent()
this.txtQRCode.Name = "txtQRCode";
this.txtQRCode.TextChanged += new System.EventHandler(this.txtQRCode_TextChanged);
//
// pbQRCode
//
resources.ApplyResources(this.pbQRCode, "pbQRCode");
this.pbQRCode.ContextMenuStrip = this.cmsQR;
this.pbQRCode.Name = "pbQRCode";
this.pbQRCode.TabStop = false;
//
// tcMain
//
this.tcMain.Controls.Add(this.tpEncode);
@ -120,11 +116,30 @@ private void InitializeComponent()
// tpEncode
//
this.tpEncode.BackColor = System.Drawing.SystemColors.Window;
this.tpEncode.Controls.Add(this.txtQRCode);
this.tpEncode.Controls.Add(this.lblQRCodeSizeHint);
this.tpEncode.Controls.Add(this.lblQRCodeSize);
this.tpEncode.Controls.Add(this.nudQRCodeSize);
this.tpEncode.Controls.Add(this.pbQRCode);
this.tpEncode.Controls.Add(this.txtQRCode);
resources.ApplyResources(this.tpEncode, "tpEncode");
this.tpEncode.Name = "tpEncode";
//
// nudQRCodeSize
//
this.nudQRCodeSize.Increment = new decimal(new int[] {
64,
0,
0,
0});
resources.ApplyResources(this.nudQRCodeSize, "nudQRCodeSize");
this.nudQRCodeSize.Maximum = new decimal(new int[] {
2048,
0,
0,
0});
this.nudQRCodeSize.Name = "nudQRCodeSize";
this.nudQRCodeSize.ValueChanged += new System.EventHandler(this.nudQRCodeSize_ValueChanged);
//
// tpDecode
//
this.tpDecode.BackColor = System.Drawing.SystemColors.Window;
@ -135,6 +150,20 @@ private void InitializeComponent()
resources.ApplyResources(this.tpDecode, "tpDecode");
this.tpDecode.Name = "tpDecode";
//
// pDecodeResult
//
resources.ApplyResources(this.pDecodeResult, "pDecodeResult");
this.pDecodeResult.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pDecodeResult.Controls.Add(this.rtbDecodeResult);
this.pDecodeResult.Name = "pDecodeResult";
//
// rtbDecodeResult
//
this.rtbDecodeResult.BorderStyle = System.Windows.Forms.BorderStyle.None;
resources.ApplyResources(this.rtbDecodeResult, "rtbDecodeResult");
this.rtbDecodeResult.Name = "rtbDecodeResult";
this.rtbDecodeResult.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.rtbDecodeResult_LinkClicked);
//
// btnDecodeFromFile
//
resources.ApplyResources(this.btnDecodeFromFile, "btnDecodeFromFile");
@ -154,19 +183,23 @@ private void InitializeComponent()
this.btnDecodeFromScreen.UseVisualStyleBackColor = true;
this.btnDecodeFromScreen.Click += new System.EventHandler(this.btnDecodeFromScreen_Click);
//
// rtbDecodeResult
// pbQRCode
//
this.rtbDecodeResult.BorderStyle = System.Windows.Forms.BorderStyle.None;
resources.ApplyResources(this.rtbDecodeResult, "rtbDecodeResult");
this.rtbDecodeResult.Name = "rtbDecodeResult";
this.rtbDecodeResult.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.rtbDecodeResult_LinkClicked);
resources.ApplyResources(this.pbQRCode, "pbQRCode");
this.pbQRCode.BackColor = System.Drawing.SystemColors.Window;
this.pbQRCode.ContextMenuStrip = this.cmsQR;
this.pbQRCode.Name = "pbQRCode";
this.pbQRCode.PictureBoxBackColor = System.Drawing.SystemColors.Window;
//
// pDecodeResult
// lblQRCodeSize
//
resources.ApplyResources(this.pDecodeResult, "pDecodeResult");
this.pDecodeResult.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pDecodeResult.Controls.Add(this.rtbDecodeResult);
this.pDecodeResult.Name = "pDecodeResult";
resources.ApplyResources(this.lblQRCodeSize, "lblQRCodeSize");
this.lblQRCodeSize.Name = "lblQRCodeSize";
//
// lblQRCodeSizeHint
//
resources.ApplyResources(this.lblQRCodeSizeHint, "lblQRCodeSizeHint");
this.lblQRCodeSizeHint.Name = "lblQRCodeSizeHint";
//
// QRCodeForm
//
@ -178,10 +211,10 @@ private void InitializeComponent()
this.Shown += new System.EventHandler(this.QRCodeForm_Shown);
this.Resize += new System.EventHandler(this.QRCodeForm_Resize);
this.cmsQR.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pbQRCode)).EndInit();
this.tcMain.ResumeLayout(false);
this.tpEncode.ResumeLayout(false);
this.tpEncode.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudQRCodeSize)).EndInit();
this.tpDecode.ResumeLayout(false);
this.tpDecode.PerformLayout();
this.pDecodeResult.ResumeLayout(false);
@ -195,7 +228,6 @@ private void InitializeComponent()
private System.Windows.Forms.ContextMenuStrip cmsQR;
private System.Windows.Forms.ToolStripMenuItem tsmiCopy;
private System.Windows.Forms.ToolStripMenuItem tsmiSaveAs;
private System.Windows.Forms.PictureBox pbQRCode;
private System.Windows.Forms.TabControl tcMain;
private System.Windows.Forms.TabPage tpEncode;
private System.Windows.Forms.TabPage tpDecode;
@ -207,5 +239,9 @@ private void InitializeComponent()
private System.Windows.Forms.ToolStripSeparator tss1;
private System.Windows.Forms.RichTextBox rtbDecodeResult;
private System.Windows.Forms.Panel pDecodeResult;
private System.Windows.Forms.NumericUpDown nudQRCodeSize;
private HelpersLib.MyPictureBox pbQRCode;
private System.Windows.Forms.Label lblQRCodeSize;
private System.Windows.Forms.Label lblQRCodeSizeHint;
}
}

View file

@ -111,7 +111,7 @@ private void ClearQRCode()
if (pbQRCode.Image != null)
{
Image temp = pbQRCode.Image;
pbQRCode.Image = null;
pbQRCode.Reset();
temp.Dispose();
}
}
@ -122,9 +122,21 @@ private void EncodeText(string text)
{
ClearQRCode();
int size = Math.Min(pbQRCode.Width, pbQRCode.Height);
pbQRCode.Image = TaskHelpers.CreateQRCode(text, size);
pbQRCode.BackColor = Color.White;
int size;
if (nudQRCodeSize.Value > 0)
{
size = (int)nudQRCodeSize.Value;
}
else
{
size = Math.Min(pbQRCode.Width, pbQRCode.Height);
}
size = Math.Max(size, 64);
Image qrCode = TaskHelpers.CreateQRCode(text, size);
pbQRCode.LoadImage(qrCode);
}
}
@ -184,7 +196,10 @@ private void DecodeFromScreen()
private void QRCodeForm_Resize(object sender, EventArgs e)
{
EncodeText(txtQRCode.Text);
if (nudQRCodeSize.Value == 0)
{
EncodeText(txtQRCode.Text);
}
}
private void txtQRCode_TextChanged(object sender, EventArgs e)
@ -192,6 +207,11 @@ private void txtQRCode_TextChanged(object sender, EventArgs e)
EncodeText(txtQRCode.Text);
}
private void nudQRCodeSize_ValueChanged(object sender, EventArgs e)
{
EncodeText(txtQRCode.Text);
}
private void tsmiCopy_Click(object sender, EventArgs e)
{
if (pbQRCode.Image != null)

View file

@ -121,15 +121,6 @@
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="cmsQR.Size" type="System.Drawing.Size, System.Drawing">
<value>181, 98</value>
</data>
<data name="&gt;&gt;cmsQR.Name" xml:space="preserve">
<value>cmsQR</value>
</data>
<data name="&gt;&gt;cmsQR.Type" xml:space="preserve">
<value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="tsmiCopy.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
</data>
@ -157,6 +148,15 @@
<data name="tsmiDecode.Text" xml:space="preserve">
<value>Decode</value>
</data>
<data name="cmsQR.Size" type="System.Drawing.Size, System.Drawing">
<value>181, 98</value>
</data>
<data name="&gt;&gt;cmsQR.Name" xml:space="preserve">
<value>cmsQR</value>
</data>
<data name="&gt;&gt;cmsQR.Type" xml:space="preserve">
<value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="txtQRCode.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
@ -172,7 +172,7 @@
<value>Both</value>
</data>
<data name="txtQRCode.Size" type="System.Drawing.Size, System.Drawing">
<value>460, 56</value>
<value>560, 56</value>
</data>
<data name="txtQRCode.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
@ -187,34 +187,109 @@
<value>tpEncode</value>
</data>
<data name="&gt;&gt;txtQRCode.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="lblQRCodeSizeHint.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="lblQRCodeSizeHint.Location" type="System.Drawing.Point, System.Drawing">
<value>221, 72</value>
</data>
<data name="lblQRCodeSizeHint.Size" type="System.Drawing.Size, System.Drawing">
<value>18, 13</value>
</data>
<data name="lblQRCodeSizeHint.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="lblQRCodeSizeHint.Text" xml:space="preserve">
<value>px</value>
</data>
<data name="&gt;&gt;lblQRCodeSizeHint.Name" xml:space="preserve">
<value>lblQRCodeSizeHint</value>
</data>
<data name="&gt;&gt;lblQRCodeSizeHint.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;lblQRCodeSizeHint.Parent" xml:space="preserve">
<value>tpEncode</value>
</data>
<data name="&gt;&gt;lblQRCodeSizeHint.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="lblQRCodeSize.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="lblQRCodeSize.Location" type="System.Drawing.Point, System.Drawing">
<value>5, 72</value>
</data>
<data name="lblQRCodeSize.Size" type="System.Drawing.Size, System.Drawing">
<value>74, 13</value>
</data>
<data name="lblQRCodeSize.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
</data>
<data name="lblQRCodeSize.Text" xml:space="preserve">
<value>QR code size:</value>
</data>
<data name="&gt;&gt;lblQRCodeSize.Name" xml:space="preserve">
<value>lblQRCodeSize</value>
</data>
<data name="&gt;&gt;lblQRCodeSize.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;lblQRCodeSize.Parent" xml:space="preserve">
<value>tpEncode</value>
</data>
<data name="&gt;&gt;lblQRCodeSize.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="nudQRCodeSize.Location" type="System.Drawing.Point, System.Drawing">
<value>136, 68</value>
</data>
<data name="nudQRCodeSize.Size" type="System.Drawing.Size, System.Drawing">
<value>80, 20</value>
</data>
<data name="nudQRCodeSize.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
</data>
<data name="nudQRCodeSize.TextAlign" type="System.Windows.Forms.HorizontalAlignment, System.Windows.Forms">
<value>Center</value>
</data>
<data name="&gt;&gt;nudQRCodeSize.Name" xml:space="preserve">
<value>nudQRCodeSize</value>
</data>
<data name="&gt;&gt;nudQRCodeSize.Type" xml:space="preserve">
<value>System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;nudQRCodeSize.Parent" xml:space="preserve">
<value>tpEncode</value>
</data>
<data name="&gt;&gt;nudQRCodeSize.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="pbQRCode.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Bottom, Left, Right</value>
</data>
<data name="pbQRCode.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 72</value>
<value>8, 96</value>
</data>
<data name="pbQRCode.Size" type="System.Drawing.Size, System.Drawing">
<value>460, 404</value>
</data>
<data name="pbQRCode.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
<value>CenterImage</value>
<value>560, 430</value>
</data>
<data name="pbQRCode.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
<value>3</value>
</data>
<data name="&gt;&gt;pbQRCode.Name" xml:space="preserve">
<value>pbQRCode</value>
</data>
<data name="&gt;&gt;pbQRCode.Type" xml:space="preserve">
<value>System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>ShareX.HelpersLib.MyPictureBox, ShareX.HelpersLib, Version=15.0.1.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;pbQRCode.Parent" xml:space="preserve">
<value>tpEncode</value>
</data>
<data name="&gt;&gt;pbQRCode.ZOrder" xml:space="preserve">
<value>1</value>
<value>3</value>
</data>
<data name="tpEncode.Location" type="System.Drawing.Point, System.Drawing">
<value>4, 22</value>
@ -223,7 +298,7 @@
<value>5, 5, 5, 5</value>
</data>
<data name="tpEncode.Size" type="System.Drawing.Size, System.Drawing">
<value>476, 485</value>
<value>576, 535</value>
</data>
<data name="tpEncode.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
@ -253,11 +328,14 @@
<value>2, 2</value>
</data>
<data name="rtbDecodeResult.Size" type="System.Drawing.Size, System.Drawing">
<value>454, 406</value>
<value>554, 456</value>
</data>
<data name="rtbDecodeResult.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="rtbDecodeResult.Text" xml:space="preserve">
<value />
</data>
<data name="&gt;&gt;rtbDecodeResult.Name" xml:space="preserve">
<value>rtbDecodeResult</value>
</data>
@ -277,7 +355,7 @@
<value>2, 2, 2, 2</value>
</data>
<data name="pDecodeResult.Size" type="System.Drawing.Size, System.Drawing">
<value>460, 412</value>
<value>560, 462</value>
</data>
<data name="pDecodeResult.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
@ -376,7 +454,7 @@
<value>3, 3, 3, 3</value>
</data>
<data name="tpDecode.Size" type="System.Drawing.Size, System.Drawing">
<value>476, 485</value>
<value>576, 535</value>
</data>
<data name="tpDecode.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
@ -403,7 +481,7 @@
<value>0, 0</value>
</data>
<data name="tcMain.Size" type="System.Drawing.Size, System.Drawing">
<value>484, 511</value>
<value>584, 561</value>
</data>
<data name="tcMain.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
@ -427,7 +505,7 @@
<value>6, 13</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>484, 511</value>
<value>584, 561</value>
</data>
<data name="$this.MinimumSize" type="System.Drawing.Size, System.Drawing">
<value>300, 300</value>

View file

@ -1985,7 +1985,7 @@ public static async Task DownloadAppVeyorBuild()
UpdateMessageBox.Start(updateChecker);
}
public static Image CreateQRCode(string text, int width, int height)
public static Image CreateQRCode(string text, int size)
{
if (CheckQRCodeContent(text))
{
@ -1996,9 +1996,12 @@ public static Image CreateQRCode(string text, int width, int height)
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Width = width,
Height = height,
CharacterSet = "UTF-8"
Width = size,
Height = size,
CharacterSet = "UTF-8",
PureBarcode = true,
NoPadding = false,
Margin = 1
},
Renderer = new BitmapRenderer()
};
@ -2014,11 +2017,6 @@ public static Image CreateQRCode(string text, int width, int height)
return null;
}
public static Image CreateQRCode(string text, int size)
{
return CreateQRCode(text, size, size);
}
public static string[] BarcodeScan(Bitmap bmp, bool scanQRCodeOnly = false)
{
try