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 System.Threading.Tasks;
|
||||||
|
using SnippingTool;
|
||||||
|
|
||||||
namespace RhSolutions.Tools;
|
namespace RhSolutions.Tools;
|
||||||
|
|
||||||
@ -24,15 +19,7 @@ internal class OcrTool : Tool
|
|||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
}).Wait();
|
}).Wait();
|
||||||
|
|
||||||
var shot = SnippingTool.SnippingTool.Snip();
|
string shot = Snipper.SnipBase64();
|
||||||
if (shot != null)
|
|
||||||
{
|
|
||||||
using MemoryStream ms = new();
|
|
||||||
shot.Save(ms, ImageFormat.Png);
|
|
||||||
byte[] imageBytes = ms.ToArray();
|
|
||||||
string base64 = Convert.ToBase64String(imageBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
Application.Visible = true;
|
Application.Visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
|
using System.Drawing.Imaging;
|
||||||
|
|
||||||
namespace SnippingTool;
|
namespace SnippingTool;
|
||||||
|
|
||||||
public partial class SnippingTool : Form
|
public partial class Snipper : Form
|
||||||
{
|
{
|
||||||
public static Image? Snip()
|
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 Bitmap bmp = new Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
|
||||||
using Graphics gr = Graphics.FromImage(bmp);
|
using Graphics gr = Graphics.FromImage(bmp);
|
||||||
gr.CopyFromScreen(0, 0, 0, 0, bmp.Size);
|
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;
|
return snipper.ShowDialog() == DialogResult.OK ? snipper.Image : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SnippingTool(Image screenShot)
|
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 Snipper(Image screenShot)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
BackgroundImage = screenShot;
|
BackgroundImage = screenShot;
|
2
SnippingTool/SnippingTool.Designer.cs
generated
2
SnippingTool/SnippingTool.Designer.cs
generated
@ -1,6 +1,6 @@
|
|||||||
namespace SnippingTool;
|
namespace SnippingTool;
|
||||||
|
|
||||||
partial class SnippingTool
|
partial class Snipper
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
|
Loading…
Reference in New Issue
Block a user