询问如何通过 Windows 命令行将桌面扩展到两个显示器时截取第二个桌面的屏幕截图

询问如何通过 Windows 命令行将桌面扩展到两个显示器时截取第二个桌面的屏幕截图

我的桌面扩展到两个显示器,我想从命令行(cmd/powershell)截取第二台显示器桌面的屏幕截图。

任何想法?

答案1

此(未经测试的)PowerShell 代码片段可以帮助您入门。请记住,对于扩展屏幕,像素坐标在两个屏幕上都是连续的,从最左侧的屏幕到最右侧的屏幕:

$File = "\mypath\myscreenshot.bmp"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = ..2nd monitor width in pixels..
$Height = ..2nd monitor height in pixels..
$Left = ..2nd monitor starting left pixel..
$Top = ..2nd monitor starting top pixel, normally zero..
# Create bitmap using the top-left and bottom-right bounds
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
# Save to file
$bitmap.Save($File) 

相关内容