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

38 lines
822 B
C#

#if !NET472
using System.Runtime.Versioning;
#endif
using System.Drawing.Imaging;
using System.IO;
using System.Threading.Tasks;
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;
}
public override void Execute()
{
Application.Visible = false;
Task.Run(async delegate
{
await Task.Delay(100);
}).Wait();
var shot = SnippingTool.SnippingTool.Snip();
if (shot != null)
{
using MemoryStream ms = new();
shot.Save(ms, ImageFormat.Png);
byte[] imageBytes = ms.ToArray();
string base64 = Convert.ToBase64String(imageBytes);
}
Application.Visible = true;
}
}