Last active
May 28, 2024 18:30
-
-
Save Santaro255/7c53a22f57784a8404e37b2b01a165b1 to your computer and use it in GitHub Desktop.
multiple monitors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
#[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.SystemParameters") | |
$bounds = [System.Windows.Forms.Screen]::PrimaryScreen | |
$w = $bounds.bounds.width#[System.Windows.SystemParameters]::VirtualScreenWidth | |
$h = $bounds.bounds.height#[System.Windows.SystemParameters]::VirtualScreenHeight | |
$img = New-Object System.Drawing.Bitmap($w, $h, [System.Drawing.Imaging.PixelFormat]::Format32bppArgb) | |
$cap = [System.Drawing.Graphics]::FromImage($img) | |
$cap.CopyFromScreen(0, 0, $bounds.Bounds.Size) | |
$img.Save("$env:USERPROFILE\screenshot.png", [System.Drawing.Imaging.ImageFormat]::Png) | |
#======================================================================================== | |
<# | |
#get desktop width | |
$w = [System.Windows.SystemParameters]::VirtualScreenWidth | |
#get desktop height | |
$h = [System.Windows.SystemParameters]::VirtualScreenHeight | |
#construct bitmap (32bit RGBA) | |
$img = New-Object System.Drawing.Bitmap($w, $h, [System.Drawing.Imaging.PixelFormat]::Format32bppArgb) | |
#create graphics image from bitmap | |
$cap = [System.Drawing.Graphics]::FromImage($img) | |
#capture screen | |
$cap.CopyFromScreen(0, 0, [System.Drawing.Size]::new($w, $h)) | |
#save captured image in png format | |
$img.Save("C:\screenshot.png", [System.Drawing.Imaging.ImageFormat]::Png) | |
#> | |
<# old | |
$bounds = [System.Windows.Forms.Screen]::PrimaryScreen | |
$w = [System.Windows.SystemParameters]::VirtualScreenWidth | |
$h = [System.Windows.SystemParameters]::VirtualScreenHeight | |
$img = New-Object System.Drawing.Bitmap($w, $h, [System.Drawing.Imaging.PixelFormat]::Format32bppArgb) | |
$cap = [System.Drawing.Graphics]::FromImage($img) | |
$cap.CopyFromScreen(0, 0, $bounds.Bounds.Size) | |
$img.Save("C:\test.png", [System.Drawing.Imaging.ImageFormat]::Png) | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment