Move base64 method to SnippingTool

This commit is contained in:
Serghei Cebotari 2024-11-08 09:03:47 +03:00
parent 29bd23a52c
commit d0c5ed5e1a
3 changed files with 21 additions and 19 deletions

View File

@ -1,10 +1,5 @@
#if !NET472
using System.Runtime.Versioning;
#endif
using System.Drawing.Imaging;
using System.IO;
using System.Threading.Tasks;
using SnippingTool;
namespace RhSolutions.Tools;
@ -24,15 +19,7 @@ internal class OcrTool : Tool
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);
}
string shot = Snipper.SnipBase64();
Application.Visible = true;
}
}

View File

@ -1,6 +1,8 @@
using System.Drawing.Imaging;
namespace SnippingTool;
public partial class SnippingTool : Form
public partial class Snipper : Form
{
public static Image? Snip()
{
@ -8,12 +10,25 @@ public partial class SnippingTool : Form
using Bitmap bmp = new Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
using Graphics gr = Graphics.FromImage(bmp);
gr.CopyFromScreen(0, 0, 0, 0, bmp.Size);
using var snipper = new SnippingTool(bmp);
using var snipper = new Snipper(bmp);
return snipper.ShowDialog() == DialogResult.OK ? snipper.Image : null;
}
public static string? SnipBase64()
{
var shot = Snip();
if (shot != null)
{
using MemoryStream ms = new();
shot.Save(ms, ImageFormat.Png);
byte[] imageBytes = ms.ToArray();
return Convert.ToBase64String(imageBytes);
}
return null;
}
public SnippingTool(Image screenShot)
public Snipper(Image screenShot)
{
InitializeComponent();
BackgroundImage = screenShot;

View File

@ -1,6 +1,6 @@
namespace SnippingTool;
partial class SnippingTool
partial class Snipper
{
/// <summary>
/// Required designer variable.