PowerShell スクショ
まずは
マルチモニターを含めた全領域のスクショ
# マルチモニター対応スクショ
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
$screens = [Windows.Forms.Screen]::AllScreens
$top = ($screens.Bounds.Top | Measure-Object -Minimum).Minimum
$left = ($screens.Bounds.Left | Measure-Object -Minimum).Minimum
$width = ($screens.Bounds.Right | Measure-Object -Maximum).Maximum
$height = ($screens.Bounds.Bottom | Measure-Object -Maximum).Maximum
$bounds = [Drawing.Rectangle]::FromLTRB($left, $top, $width, $height)
$bitmap = New-Object System.Drawing.Bitmap ([int]$bounds.width), ([int]$bounds.height)
$graphics = [Drawing.Graphics]::FromImage($bitmap)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bitmap.Save("c:\temp\multi.png", [System.Drawing.Imaging.ImageFormat]::Png)
$graphics.Dispose()
$bitmap.Dispose()
スクショを取ってCドライブのtempフォルダにmulti.pngとして保存されます。
[System.Drawing.Imaging.ImageFormat]::Pngのところを
[System.Drawing.Imaging.ImageFormat]::Jpegに書き換えるとJPEGで保存できます。
メインスクリーンのみスクショ
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
$screen = [Windows.Forms.Screen]::PrimaryScreen
$top = $screen.Bounds.Top
$left = $screen.Bounds.Left
$right = $screen.Bounds.Right
$bottom = $screen.Bounds.Bottom
$bounds = [Drawing.Rectangle]::FromLTRB($left, $top, $right, $bottom)
$bitmap = New-Object System.Drawing.Bitmap ([int]$bounds.width), ([int]$bounds.height)
$graphics = [Drawing.Graphics]::FromImage($bitmap)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save("c:\temp\main.png", [System.Drawing.Imaging.ImageFormat]::Png)
$graphics.Dispose()
$bitmap.Dispose()
#PowerShell #コマンドレット #スクショ #マルチモニター対応 #Windows #プログラミング #プログラミング初心者 #毎日Note
この記事が気に入ったらサポートをしてみませんか?