mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Added OCRLanguage class
This commit is contained in:
parent
6058243263
commit
dfdcf75100
5 changed files with 68 additions and 10 deletions
1
ShareX/Forms/OCRForm.Designer.cs
generated
1
ShareX/Forms/OCRForm.Designer.cs
generated
|
@ -51,6 +51,7 @@ private void InitializeComponent()
|
|||
this.cbLanguages.Name = "cbLanguages";
|
||||
this.cbLanguages.Size = new System.Drawing.Size(216, 21);
|
||||
this.cbLanguages.TabIndex = 1;
|
||||
this.cbLanguages.SelectedIndexChanged += new System.EventHandler(this.cbLanguages_SelectedIndexChanged);
|
||||
//
|
||||
// lblResult
|
||||
//
|
||||
|
|
|
@ -25,15 +25,14 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using ShareX.HelpersLib;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Windows.Media.Ocr;
|
||||
|
||||
namespace ShareX
|
||||
{
|
||||
public partial class OCRForm : Form
|
||||
{
|
||||
public OCRLanguage Language { get; set; }
|
||||
public string Result { get; private set; }
|
||||
|
||||
private Stream stream;
|
||||
|
@ -45,19 +44,14 @@ public OCRForm(Stream stream)
|
|||
InitializeComponent();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
|
||||
cbLanguages.Items.AddRange(OcrEngine.AvailableRecognizerLanguages.Select(x => x.DisplayName).ToArray());
|
||||
cbLanguages.Items.AddRange(OCRHelper.AvailableLanguages);
|
||||
cbLanguages.SelectedIndex = 0;
|
||||
txtResult.SupportSelectAll();
|
||||
}
|
||||
|
||||
private async void OCRForm_Shown(object sender, System.EventArgs e)
|
||||
private async Task OCR(string languageTag)
|
||||
{
|
||||
await OCR();
|
||||
}
|
||||
|
||||
private async Task OCR()
|
||||
{
|
||||
Result = await OCRHelper.OCR(stream);
|
||||
Result = await OCRHelper.OCR(stream, languageTag);
|
||||
|
||||
if (!IsDisposed)
|
||||
{
|
||||
|
@ -65,5 +59,15 @@ private async Task OCR()
|
|||
txtResult.Text = Result;
|
||||
}
|
||||
}
|
||||
|
||||
private async void OCRForm_Shown(object sender, System.EventArgs e)
|
||||
{
|
||||
await OCR(Language.LanguageTag);
|
||||
}
|
||||
|
||||
private void cbLanguages_SelectedIndexChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
Language = cbLanguages.SelectedItem as OCRLanguage;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,6 +44,14 @@ public static bool IsSupported
|
|||
}
|
||||
}
|
||||
|
||||
public static OCRLanguage[] AvailableLanguages
|
||||
{
|
||||
get
|
||||
{
|
||||
return OcrEngine.AvailableRecognizerLanguages.Select(x => new OCRLanguage(x.DisplayName, x.LanguageTag)).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ThrowIfNotSupported()
|
||||
{
|
||||
if (!IsSupported)
|
||||
|
|
44
ShareX/OCRLanguage.cs
Normal file
44
ShareX/OCRLanguage.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2022 ShareX Team
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
namespace ShareX
|
||||
{
|
||||
public class OCRLanguage
|
||||
{
|
||||
public string DisplayName { get; set; }
|
||||
public string LanguageTag { get; set; }
|
||||
|
||||
public OCRLanguage(string displayName, string languageTag)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
LanguageTag = languageTag;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return DisplayName;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -208,6 +208,7 @@
|
|||
</Compile>
|
||||
<Compile Include="NotificationFormConfig.cs" />
|
||||
<Compile Include="OCRHelper.cs" />
|
||||
<Compile Include="OCRLanguage.cs" />
|
||||
<Compile Include="SettingManager.cs" />
|
||||
<Compile Include="Forms\BeforeUploadForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
|
Loading…
Reference in a new issue