Skip to content

Instantly share code, notes, and snippets.

@Raffy27
Last active April 21, 2021 11:21
Show Gist options
  • Save Raffy27/37d2742d8b8076b190efe39b9658ccf0 to your computer and use it in GitHub Desktop.
Save Raffy27/37d2742d8b8076b190efe39b9658ccf0 to your computer and use it in GitHub Desktop.
Screenshot with variable dimensions
[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()
}
$w = (Get-WmiObject -Class Win32_VideoController).VideoModeDescription.Split("x");
$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, [int]$w[0].Trim(), [int]$w[1].Trim())
screenshot $bounds "C:\.hydra\sc.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment