mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
Just an experimental feature, doing an OCR in the capture form.
This commit is contained in:
parent
b49b01c9be
commit
5222d3e562
1 changed files with 57 additions and 24 deletions
|
@ -32,7 +32,10 @@ using System.Drawing.Drawing2D;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Security.Permissions;
|
using System.Security.Permissions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Windows.Threading;
|
||||||
using GreenshotPlugin.IniFile;
|
using GreenshotPlugin.IniFile;
|
||||||
using GreenshotPlugin.Interfaces;
|
using GreenshotPlugin.Interfaces;
|
||||||
|
|
||||||
|
@ -302,6 +305,22 @@ namespace Greenshot.Forms {
|
||||||
ToFront = !ToFront;
|
ToFront = !ToFront;
|
||||||
TopMost = !TopMost;
|
TopMost = !TopMost;
|
||||||
break;
|
break;
|
||||||
|
case Keys.O:
|
||||||
|
if (_capture.OcrInformation is null)
|
||||||
|
{
|
||||||
|
var ocrProvider = SimpleServiceProvider.Current.GetInstance<IOcrProvider>();
|
||||||
|
if (ocrProvider is object)
|
||||||
|
{
|
||||||
|
var uiTaskScheduler = SimpleServiceProvider.Current.GetInstance<TaskScheduler>();
|
||||||
|
|
||||||
|
Task.Factory.StartNew(async () =>
|
||||||
|
{
|
||||||
|
_capture.OcrInformation = await ocrProvider.DoOcrAsync(_capture.Image);
|
||||||
|
Invalidate();
|
||||||
|
}, CancellationToken.None, TaskCreationOptions.None, uiTaskScheduler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,6 +717,20 @@ namespace Greenshot.Forms {
|
||||||
Rectangle clipRectangle = e.ClipRectangle;
|
Rectangle clipRectangle = e.ClipRectangle;
|
||||||
//graphics.BitBlt((Bitmap)buffer, Point.Empty);
|
//graphics.BitBlt((Bitmap)buffer, Point.Empty);
|
||||||
graphics.DrawImageUnscaled(_capture.Image, Point.Empty);
|
graphics.DrawImageUnscaled(_capture.Image, Point.Empty);
|
||||||
|
|
||||||
|
var ocrInfo = _capture.OcrInformation;
|
||||||
|
if (ocrInfo != null)
|
||||||
|
{
|
||||||
|
using var pen = new Pen(Color.Red);
|
||||||
|
foreach (var line in ocrInfo.Lines)
|
||||||
|
{
|
||||||
|
var lineBounds = line.CalculatedBounds;
|
||||||
|
if (!lineBounds.IsEmpty)
|
||||||
|
{
|
||||||
|
graphics.DrawRectangle(pen, line.CalculatedBounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Only draw Cursor if it's (partly) visible
|
// Only draw Cursor if it's (partly) visible
|
||||||
if (_capture.Cursor != null && _capture.CursorVisible && clipRectangle.IntersectsWith(new Rectangle(_capture.CursorLocation, _capture.Cursor.Size))) {
|
if (_capture.Cursor != null && _capture.CursorVisible && clipRectangle.IntersectsWith(new Rectangle(_capture.CursorLocation, _capture.Cursor.Size))) {
|
||||||
graphics.DrawIcon(_capture.Cursor, _capture.CursorLocation.X, _capture.CursorLocation.Y);
|
graphics.DrawIcon(_capture.Cursor, _capture.CursorLocation.X, _capture.CursorLocation.Y);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue