NetAutoGUI/ScreenshotExtensions.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Diagnostics;
using System.Linq;
namespace NetAutoGUI
{
public static class ScreenshotExtensions
{
public static BitmapData Screenshot(this IScreenshotController ctl, Window window, uint screenIndex = 0)
{
var rect = window.Rectangle;
return ctl.Screenshot(rect, screenIndex);
//todo: enable the screenshot of invisible window by IGraphicsCaptureItemInterop
//https://blogs.windows.com/windowsdeveloper/2019/09/16/new-ways-to-do-screen-capture/
}
public static Rectangle? LocateOnScreen(this IScreenshotController ctl, string imgFileToBeFound, double confidence = 0.99, uint screenIndex = 0)
{
var items = LocateAllOnScreen(ctl, imgFileToBeFound, confidence, screenIndex: screenIndex);
if (items.Length <= 0)
{
return null;
}
else
{
return items[0];
}
}
public static Rectangle WaitOnScreen(this IScreenshotController ctl, string imgFileToBeFound, double confidence = 0.99, double timeoutSeconds = 5, uint screenIndex = 0)
{
Stopwatch sw = new Stopwatch();
sw.Start();
Rectangle? rect = null;
while (sw.ElapsedMilliseconds < timeoutSeconds * 1000 && rect == null)
{
rect = LocateAllOnScreen(ctl, imgFileToBeFound, confidence, screenIndex: screenIndex).FirstOrDefault();
}
if (rect == null)
{
throw new InvalidOperationException($"image {imgFileToBeFound} not found on the screen");
}
else
{
return rect;
}
}
public static Rectangle[] LocateAllOnScreen(this IScreenshotController ctrl, string imgFileToBeFound, double confidence = 0.99, uint screenIndex = 0)
{
var bitmapScreen = ctrl.Screenshot(screenIndex: screenIndex);
return ctrl.LocateAll(bitmapScreen, imgFileToBeFound, confidence);
}
public static void Highlight(this IScreenshotController ctl, string imgFileToBeFound, double confidence = 0.99, double waitSeconds = 0.5, uint screenIndex = 0)
{
var rects = LocateAllOnScreen(ctl, imgFileToBeFound, confidence, screenIndex: screenIndex);
ctl.Highlight(waitSeconds, rects);
}
}
后面还有 1 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。