目前,Microsoft并未发布Windows.Graphics.Capture API的Delphi版本。不过,我们可以使用WinRT API来在Delphi中访问Windows.Graphics.Capture API。下面是一个简单的示例代码,展示如何在Delphi中使用WinRT API来捕获屏幕:
uses
Winapi.Windows,
Winapi.ActiveX,
System.Win.WinRT,
System.Win.WinRTEx;
procedure TForm1.CaptureScreen;
var
screenRect: Windows.TRect;
captureItem: Windows.Graphics.Capture.GraphicsCaptureItem;
framePool: Windows.Graphics.Capture.Direct3D11.GraphicsCaptureFramePool;
session: Windows.Graphics.Capture.Direct3D11.GraphicsCaptureSession;
begin
screenRect := Windows.GetBoundsForMonitor(Windows.MonitorFromWindow(Self.Handle, MONITOR_DEFAULTTONEAREST));
captureItem := Windows.Graphics.Capture.GraphicsCaptureItem.CreateFromVisual(WindowHandle);
framePool := Windows.Graphics.Capture.Direct3D11.GraphicsCaptureFramePool.Create(
Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, screenRect.Size);
session := Windows.Graphics.Capture.Direct3D11.GraphicsCaptureSession.Create(
framePool, captureItem);
framePool.StartCapture;
session.StartCapture;
// do something with captured frames...
session.Close;
framePool.Close;
end;
该代码中的CaptureScreen过程使用Windows API来获取屏幕矩形,并使用WinRT API来捕获该矩形的图像。注意,这个示例代码仅演示如何使用WinRT API来访问Windows.Graphics.Capture API,并不包含完整的屏幕捕获功能。