From 21232e48ef745ee48129123294bd5f7967742e71 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sun, 28 Jul 2024 13:50:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=A7=A3=E6=9E=90=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E5=9D=90=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArtemisFgTools/Program.cs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ArtemisFgTools/Program.cs b/ArtemisFgTools/Program.cs index 9d0eecc..22ae688 100644 --- a/ArtemisFgTools/Program.cs +++ b/ArtemisFgTools/Program.cs @@ -1,5 +1,6 @@ using ImageMagick; using NLua; +using System.Text.RegularExpressions; namespace ArtemisFgTools { internal class Program @@ -44,8 +45,7 @@ namespace ArtemisFgTools } Console.WriteLine($"fg count: {fgObjects.Count}"); //Todo: Combine fgObjects with image position - //Todo: Get image position from png comment - String comment = ReadPngComment("G:/x221.local/fg/baa/fa/a0001.png"); + List comment = ReadPngComment("G:/x221.local/fg/baa/fa/a0001.png"); } else @@ -164,16 +164,30 @@ namespace ArtemisFgTools return result; } - public static string ReadPngComment(string filePath) + public static List ReadPngComment(string filePath) { if (File.Exists(filePath)) { // Read image from file using var image = new MagickImage(filePath); - if(image.Comment != null) + if (image.Comment != null) { - return image.Comment; + string pattern = @"^pos,(\d+),(\d+),(\d+),(\d+)$"; + Match match = Regex.Match(image.Comment, pattern); + if (match.Success) + { + int x = int.Parse(match.Groups[1].Value); + int y = int.Parse(match.Groups[2].Value); + int w = int.Parse(match.Groups[3].Value); + int h = int.Parse(match.Groups[4].Value); + + return [x, y, w, h]; + } + else + { + throw new Exception("Unexpected result"); + } } else { @@ -182,7 +196,7 @@ namespace ArtemisFgTools } else { - Console.WriteLine("File does not exist."); + throw new Exception("File does not exist."); } }