Move base64 method to SnippingTool
This commit is contained in:
parent
29bd23a52c
commit
d0c5ed5e1a
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
2
SnippingTool/SnippingTool.Designer.cs
generated
2
SnippingTool/SnippingTool.Designer.cs
generated
@ -1,6 +1,6 @@
|
||||
namespace SnippingTool;
|
||||
|
||||
partial class SnippingTool
|
||||
partial class Snipper
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
|
Loading…
Reference in New Issue
Block a user