Skip to content

Commit

Permalink
Update ScreenMatch.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
gnh1201 committed Nov 3, 2024
1 parent b2975e0 commit a8a13b5
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,14 @@ public List<ScreenMatchResult> CaptureAndMatchAllScreens()
Screen screen = Screen.AllScreens[i];
Bitmap mainImage = CaptureScreen(screen);

Bitmap image = templateImages[templateCurrentIndex];
string templateName = image.Tag as string;
Bitmap templateImage = templateImages[templateCurrentIndex];
string templateName = templateImage.Tag as string;
TemplateInfo nextTemplateInfo = parent.GetNextTemplateInfo();

Size templateSize = new Size
{
Width = image.Width,
Height = image.Height
Width = templateImage.Width,
Height = templateImage.Height
};

logger.LogInformation($"Trying match the template {templateName} on the screen {i}...");
Expand Down Expand Up @@ -505,22 +505,20 @@ public List<ScreenMatchResult> CaptureAndMatchAllScreens()
// If the index value is negative, retrieve and use an outdated image from the queue
if (nextTemplateInfo.Index < 0)
{
Bitmap outdatedImage = null;

logger.LogInformation($"Finding a previous screen of {nextTemplateInfo.FileName}...");

Bitmap outdatedImage = null;
try
{
while (outdatedSamples.Count > 0)
// Since outdatedSamples is also used to detect duplicate work, we do not delete tasks with Dequeue.
foreach (var image in outdatedSamples)
{
outdatedImage = outdatedSamples.Dequeue();
if (outdatedImage.Tag != null)
if (image.Tag != null &&
((SampleInfo)image.Tag).FileName == nextTemplateInfo.FileName)
{
if (((SampleInfo)outdatedImage.Tag).FileName == nextTemplateInfo.FileName)
{
logger.LogInformation($"Found the previous screen of {nextTemplateInfo.FileName}");
break;
}
outdatedImage = image;
logger.LogInformation($"Found the previous screen of {nextTemplateInfo.FileName}");
break;
}
}
}
Expand Down Expand Up @@ -550,7 +548,7 @@ public List<ScreenMatchResult> CaptureAndMatchAllScreens()
else
{
// If the index is not negative, use the current image for template matching
matchPositions = FindTemplate(out_mainImage, (Bitmap)image.Clone());
matchPositions = FindTemplate(out_mainImage, (Bitmap)templateImage.Clone());
}

foreach (Point matchPosition in matchPositions)
Expand Down

0 comments on commit a8a13b5

Please sign in to comment.