Update ScreenMatch.cs

This commit is contained in:
Namhyeon Go 2024-09-18 15:01:05 +09:00
parent 27e9a328d4
commit c36d7fb71f

View File

@ -369,8 +369,6 @@ public class ScreenMatch
} }
Bitmap image = templateImages[templateCurrentIndex]; Bitmap image = templateImages[templateCurrentIndex];
parent.Log($"Trying match the template {image.Tag as string} on the screen {i}...");
string templateName = image.Tag as string; string templateName = image.Tag as string;
Size templateSize = new Size Size templateSize = new Size
{ {
@ -378,6 +376,8 @@ public class ScreenMatch
Height = image.Height Height = image.Height
}; };
parent.Log($"Trying match the template {templateName} on the screen {i}...");
Bitmap _mainImage; Bitmap _mainImage;
if (templateName.StartsWith("binary_")) if (templateName.StartsWith("binary_"))
{ {
@ -398,7 +398,7 @@ public class ScreenMatch
results.Add(new ScreenMatchResult results.Add(new ScreenMatchResult
{ {
FileName = image.Tag.ToString(), FileName = templateName,
ScreenNumber = i, ScreenNumber = i,
Position = matchPosition, Position = matchPosition,
Text = text Text = text
@ -559,10 +559,21 @@ public class ScreenMatch
if (windowImage != null) if (windowImage != null)
{ {
Bitmap image = templateImages[templateCurrentIndex]; Bitmap image = templateImages[templateCurrentIndex];
string templateName = image.Tag as string;
Size templateSize = new Size
{
Width = image.Width,
Height = image.Height
};
List<Point> matchPositions = FindTemplate(windowImage, image); List<Point> matchPositions = FindTemplate(windowImage, image);
matchPositions.ForEach((matchPosition) => matchPositions.ForEach((matchPosition) =>
{ {
string templateName = image.Tag as string; try
{
string text = sampleAny.Contains(templateName) ?
InspectSample((Bitmap)windowImage.Clone(), matchPosition, templateSize, templateName, sampleSize) : string.Empty;
results.Add(new ScreenMatchResult results.Add(new ScreenMatchResult
{ {
FileName = templateName, FileName = templateName,
@ -570,8 +581,14 @@ public class ScreenMatch
WindowTitle = windowTitle, WindowTitle = windowTitle,
ProcessName = processName, ProcessName = processName,
WindowPosition = windowPosition, WindowPosition = windowPosition,
Position = matchPosition Position = matchPosition,
Text = text
}); });
}
catch (Exception ex)
{
parent.Log($"Ignore the match. {ex.Message}");
}
}); });
} }
} }