mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
Added "Select region" button to OCR window
This commit is contained in:
parent
11d4dc8b5a
commit
a349925bbc
5 changed files with 78 additions and 31 deletions
1
ShareX/Forms/AutoCaptureForm.Designer.cs
generated
1
ShareX/Forms/AutoCaptureForm.Designer.cs
generated
|
@ -180,7 +180,6 @@ private void InitializeComponent()
|
|||
// AutoCaptureForm
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.Controls.Add(this.gbRegion);
|
||||
|
|
|
@ -270,7 +270,7 @@
|
|||
<value>2</value>
|
||||
</data>
|
||||
<data name="btnRegion.Text" xml:space="preserve">
|
||||
<value>Select region</value>
|
||||
<value>Select region...</value>
|
||||
</data>
|
||||
<data name=">>btnRegion.Name" xml:space="preserve">
|
||||
<value>btnRegion</value>
|
||||
|
@ -451,7 +451,7 @@
|
|||
<value>True</value>
|
||||
</metadata>
|
||||
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
|
||||
<value>6, 13</value>
|
||||
<value>96, 96</value>
|
||||
</data>
|
||||
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
|
||||
<value>319, 263</value>
|
||||
|
|
25
ShareX/OCR/OCRForm.Designer.cs
generated
25
ShareX/OCR/OCRForm.Designer.cs
generated
|
@ -7,19 +7,6 @@ partial class OCRForm
|
|||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
|
@ -40,6 +27,7 @@ private void InitializeComponent()
|
|||
this.cbEditServices = new System.Windows.Forms.Button();
|
||||
this.pbStatus = new System.Windows.Forms.ProgressBar();
|
||||
this.lblStatus = new System.Windows.Forms.Label();
|
||||
this.btnSelectRegion = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudScaleFactor)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
|
@ -82,7 +70,7 @@ private void InitializeComponent()
|
|||
0,
|
||||
65536});
|
||||
this.nudScaleFactor.Maximum = new decimal(new int[] {
|
||||
5,
|
||||
4,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
|
@ -134,10 +122,18 @@ private void InitializeComponent()
|
|||
resources.ApplyResources(this.lblStatus, "lblStatus");
|
||||
this.lblStatus.Name = "lblStatus";
|
||||
//
|
||||
// btnSelectRegion
|
||||
//
|
||||
resources.ApplyResources(this.btnSelectRegion, "btnSelectRegion");
|
||||
this.btnSelectRegion.Name = "btnSelectRegion";
|
||||
this.btnSelectRegion.UseVisualStyleBackColor = true;
|
||||
this.btnSelectRegion.Click += new System.EventHandler(this.btnSelectRegion_Click);
|
||||
//
|
||||
// OCRForm
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.btnSelectRegion);
|
||||
this.Controls.Add(this.lblStatus);
|
||||
this.Controls.Add(this.pbStatus);
|
||||
this.Controls.Add(this.cbEditServices);
|
||||
|
@ -171,5 +167,6 @@ private void InitializeComponent()
|
|||
private System.Windows.Forms.Button cbEditServices;
|
||||
private System.Windows.Forms.ProgressBar pbStatus;
|
||||
private System.Windows.Forms.Label lblStatus;
|
||||
private System.Windows.Forms.Button btnSelectRegion;
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.ScreenCaptureLib;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -36,13 +37,13 @@ public partial class OCRForm : Form
|
|||
public OCROptions Options { get; set; }
|
||||
public string Result { get; private set; }
|
||||
|
||||
private Bitmap bmp;
|
||||
private Bitmap bmpSource;
|
||||
private bool loaded;
|
||||
private bool busy;
|
||||
|
||||
public OCRForm(Bitmap bmp, OCROptions options)
|
||||
{
|
||||
this.bmp = bmp;
|
||||
bmpSource = (Bitmap)bmp.Clone();
|
||||
Options = options;
|
||||
|
||||
InitializeComponent();
|
||||
|
@ -97,8 +98,20 @@ public OCRForm(Bitmap bmp, OCROptions options)
|
|||
loaded = true;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
components?.Dispose();
|
||||
bmpSource?.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void UpdateControls()
|
||||
{
|
||||
btnSelectRegion.Visible = !busy;
|
||||
lblLanguage.Visible = !busy;
|
||||
cbLanguages.Visible = !busy;
|
||||
lblScaleFactor.Visible = !busy;
|
||||
|
@ -109,12 +122,12 @@ private void UpdateControls()
|
|||
|
||||
private async Task OCR()
|
||||
{
|
||||
if (bmp != null && !string.IsNullOrEmpty(Options.Language))
|
||||
if (bmpSource != null && !string.IsNullOrEmpty(Options.Language))
|
||||
{
|
||||
busy = true;
|
||||
UpdateControls();
|
||||
|
||||
Result = await OCRHelper.OCR(bmp, Options.Language, Options.ScaleFactor);
|
||||
Result = await OCRHelper.OCR(bmpSource, Options.Language, Options.ScaleFactor);
|
||||
|
||||
if (Options.AutoCopy && !string.IsNullOrEmpty(Result))
|
||||
{
|
||||
|
@ -135,6 +148,17 @@ private async void OCRForm_Shown(object sender, EventArgs e)
|
|||
await OCR();
|
||||
}
|
||||
|
||||
private async void btnSelectRegion_Click(object sender, EventArgs e)
|
||||
{
|
||||
WindowState = FormWindowState.Minimized;
|
||||
await Task.Delay(250);
|
||||
bmpSource?.Dispose();
|
||||
bmpSource = RegionCaptureTasks.GetRegionImage(new RegionCaptureOptions());
|
||||
WindowState = FormWindowState.Normal;
|
||||
|
||||
await OCR();
|
||||
}
|
||||
|
||||
private async void cbLanguages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (loaded)
|
||||
|
|
|
@ -147,7 +147,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>lblLanguage.ZOrder" xml:space="preserve">
|
||||
<value>10</value>
|
||||
<value>11</value>
|
||||
</data>
|
||||
<data name="cbLanguages.Font" type="System.Drawing.Font, System.Drawing">
|
||||
<value>Microsoft Sans Serif, 9.75pt</value>
|
||||
|
@ -171,7 +171,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>cbLanguages.ZOrder" xml:space="preserve">
|
||||
<value>9</value>
|
||||
<value>10</value>
|
||||
</data>
|
||||
<data name="lblResult.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
|
@ -201,7 +201,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>lblResult.ZOrder" xml:space="preserve">
|
||||
<value>8</value>
|
||||
<value>9</value>
|
||||
</data>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="txtResult.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
|
@ -235,7 +235,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>txtResult.ZOrder" xml:space="preserve">
|
||||
<value>7</value>
|
||||
<value>8</value>
|
||||
</data>
|
||||
<data name="lblScaleFactor.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
|
@ -265,7 +265,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>lblScaleFactor.ZOrder" xml:space="preserve">
|
||||
<value>6</value>
|
||||
<value>7</value>
|
||||
</data>
|
||||
<data name="nudScaleFactor.Font" type="System.Drawing.Font, System.Drawing">
|
||||
<value>Microsoft Sans Serif, 9.75pt</value>
|
||||
|
@ -292,7 +292,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>nudScaleFactor.ZOrder" xml:space="preserve">
|
||||
<value>5</value>
|
||||
<value>6</value>
|
||||
</data>
|
||||
<data name="cbServices.Font" type="System.Drawing.Font, System.Drawing">
|
||||
<value>Microsoft Sans Serif, 9.75pt</value>
|
||||
|
@ -316,7 +316,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>cbServices.ZOrder" xml:space="preserve">
|
||||
<value>4</value>
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name="btnOpen.Enabled" type="System.Boolean, mscorlib">
|
||||
<value>False</value>
|
||||
|
@ -346,7 +346,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>btnOpen.ZOrder" xml:space="preserve">
|
||||
<value>3</value>
|
||||
<value>4</value>
|
||||
</data>
|
||||
<data name="cbEditServices.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>568, 48</value>
|
||||
|
@ -367,7 +367,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>cbEditServices.ZOrder" xml:space="preserve">
|
||||
<value>2</value>
|
||||
<value>3</value>
|
||||
</data>
|
||||
<data name="pbStatus.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>16, 40</value>
|
||||
|
@ -388,7 +388,7 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>pbStatus.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
</data>
|
||||
<data name="lblStatus.AutoSize" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
|
@ -418,6 +418,33 @@
|
|||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>lblStatus.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name="btnSelectRegion.Font" type="System.Drawing.Font, System.Drawing">
|
||||
<value>Microsoft Sans Serif, 9.75pt</value>
|
||||
</data>
|
||||
<data name="btnSelectRegion.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>128, -2</value>
|
||||
</data>
|
||||
<data name="btnSelectRegion.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>160, 32</value>
|
||||
</data>
|
||||
<data name="btnSelectRegion.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>11</value>
|
||||
</data>
|
||||
<data name="btnSelectRegion.Text" xml:space="preserve">
|
||||
<value>Select region...</value>
|
||||
</data>
|
||||
<data name=">>btnSelectRegion.Name" xml:space="preserve">
|
||||
<value>btnSelectRegion</value>
|
||||
</data>
|
||||
<data name=">>btnSelectRegion.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>btnSelectRegion.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>btnSelectRegion.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
|
|
Loading…
Reference in a new issue