Powershell ScreenShot的特定部分 [英] Powershell ScreenShot of a particular part

查看:41
本文介绍了Powershell ScreenShot的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想截取屏幕上非常特殊的部分的屏幕截图.好像我只是想在屏幕中央拍摄一张图像的屏幕快照.我怎样才能做到这一点?如何设置对齐方式以仅裁剪特定区域.我从stackoverflow获得代码只是为了截屏:

I want to take a screenshot of a very particular part of the screen. As if I just want to take a screenshot of an image in the centre of the screen. How can I do that? How can I setthe alignment to only crop a particular area. I got the code from stackoverflow only to take a screenshot:

[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
   $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
   $graphics = [Drawing.Graphics]::FromImage($bmp)

   $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)

   $bmp.Save($path)

   $graphics.Dispose()
   $bmp.Dispose()
}

$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1000, 900)
screenshot $bounds "C:\screenshot.jpeg"

如果我们可以编辑它.

推荐答案

我在这里做了一些事情,以制作胡扯和欢笑,以截取屏幕上居中的矩形的屏幕截图.

For craps and laughter I made something here that will make a screenshot of a rectangle that is centered on the screen.

$captureSize = @{ Height = 300; Width = 200}
$screenDimensions = Get-WmiObject -Class Win32_DesktopMonitor | Select-Object -First 1 ScreenWidth,ScreenHeight
$screenCenterPoint = @{FromTop = ($screenDimensions.ScreenHeight) / 2; FromLeft = ($screenDimensions.ScreenWidth) /2 }
$box = @{}
$box.Left = $screenCenterPoint.FromLeft - $captureSize.Width / 2
$box.Top = $screenCenterPoint.FromTop - $captureSize.Height / 2
$box.Right = $box.Left + $captureSize.Width
$box.Bottom = $box.Top + $captureSize.Height

$bounds = [Drawing.Rectangle]::FromLTRB($box.Left,$box.Top,$box.Right,$box.Bottom)

$ captureSize 设置为所需的值.使用由Alpha M Cubed链接的SO问题获取屏幕分辨率在Windows 7中使用WMI/powershell ,我们将主屏幕"尺寸填充到 $ screenDimensions 中.使用一些简单的数学却没有错误检测,我们可以算出盒子相对于屏幕中心的位置.函数和函数调用保持不变.

Set $captureSize to the values that you want. Using the SO question that was linked by Alpha M Cubed Get Screen resolution using WMI/powershell in Windows 7 we populate the "primary screen" dimensions into $screenDimensions. Using some simple math with no error detection what so ever we figure the location of the box relative to the center of the screen. The function and function call stay the same.

这篇关于Powershell ScreenShot的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆