RhSolutions-AddIn/RhSolutions.AddIn/Tools/OcrTool.cs

38 lines
822 B
C#
Raw Normal View History

2024-11-06 23:43:00 +03:00
#if !NET472
using System.Runtime.Versioning;
#endif
2024-11-07 23:32:39 +03:00
using System.Drawing.Imaging;
using System.IO;
using System.Threading.Tasks;
2024-11-06 23:43:00 +03:00
namespace RhSolutions.Tools;
internal class OcrTool : Tool
{
public Application Application { get; set; }
public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory, Application application) : base(readerFactory, writerFactory)
{
Application = application;
}
2024-11-06 23:43:00 +03:00
public override void Execute()
{
Application.Visible = false;
Task.Run(async delegate
{
await Task.Delay(100);
}).Wait();
2024-11-07 23:32:39 +03:00
var shot = SnippingTool.SnippingTool.Snip();
if (shot != null)
2024-11-06 23:43:00 +03:00
{
2024-11-07 23:32:39 +03:00
using MemoryStream ms = new();
shot.Save(ms, ImageFormat.Png);
byte[] imageBytes = ms.ToArray();
string base64 = Convert.ToBase64String(imageBytes);
2024-11-06 23:43:00 +03:00
}
Application.Visible = true;
2024-11-06 23:43:00 +03:00
}
}