locked
Save Desktop to Image File RRS feed

  • Question

  • I use the following to save a screenshot to an image file ok on my laptop. But the desktop image will be cut off by about 20% on the right and the bottom when using a PC with dual monitors. Anyway can solve the issue? Thanks.

    Add-type -AssemblyName System.Drawing
    $s = [System.Windows.Forms.SystemInformation]::VirtualScreen
    $bmp = New-Object System.Drawing.Bitmap $s.Width, $s.Height
    $graphic = [System.Drawing.Graphics]::FromImage($bmp)
    $graphic.CopyFromScreen($s.Left, $s.Top, 0, 0, $bmp.Size)
    $bmp.Save('C:\Temp\desktop.bmp')

    Tuesday, March 20, 2018 4:12 PM

Answers

  • Found this solution from here

    [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, 6000, 900)
    screenshot $bounds "C:\Users\harwoodm\Desktop\testing.png"
    Just change the last two numbers in $bounds to change the size of the capture.


    Learn PowerShell

    Script Requests

    -Remember to mark the correct response as the answer-

    Tuesday, March 20, 2018 4:34 PM