diff options
author | Serghei Cebotari <serghei@cebotari.ru> | 2024-11-08 09:03:47 +0300 |
---|---|---|
committer | Serghei Cebotari <serghei@cebotari.ru> | 2024-11-08 09:03:47 +0300 |
commit | d0c5ed5e1ac82668de8851de713928c4334e7881 (patch) | |
tree | 9c851650901b3719b48bf2d3684504cba288b283 | |
parent | 29bd23a52ce52fbe25dc6e738e5a47c156fb41ec (diff) |
Move base64 method to SnippingTool
-rw-r--r-- | RhSolutions.AddIn/Tools/OcrTool.cs | 17 | ||||
-rw-r--r-- | SnippingTool/Snipper.cs (renamed from SnippingTool/SnippingTool.cs) | 21 | ||||
-rw-r--r-- | SnippingTool/SnippingTool.Designer.cs | 2 |
3 files changed, 21 insertions, 19 deletions
diff --git a/RhSolutions.AddIn/Tools/OcrTool.cs b/RhSolutions.AddIn/Tools/OcrTool.cs index a30b27c..f407db8 100644 --- a/RhSolutions.AddIn/Tools/OcrTool.cs +++ b/RhSolutions.AddIn/Tools/OcrTool.cs @@ -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; } }
\ No newline at end of file diff --git a/SnippingTool/SnippingTool.cs b/SnippingTool/Snipper.cs index bd08076..0f5e9cc 100644 --- a/SnippingTool/SnippingTool.cs +++ b/SnippingTool/Snipper.cs @@ -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; diff --git a/SnippingTool/SnippingTool.Designer.cs b/SnippingTool/SnippingTool.Designer.cs index 322a511..a170216 100644 --- a/SnippingTool/SnippingTool.Designer.cs +++ b/SnippingTool/SnippingTool.Designer.cs @@ -1,6 +1,6 @@ namespace SnippingTool; -partial class SnippingTool +partial class Snipper { /// <summary> /// Required designer variable. |