Reputation: 11
I have the batch file below which takes a screenshot every 5 seconds. This works well however I want to specify only a part of the display from which to take the screenshot using coordinates. I do not want the entire display to be captured. For example, assuming the bottom left corner is 0,0, I want to capture from 100,100 (bottom left corner) to 1000,1000 (top right comer). How do I modify the batch file to do this?
@echo off
REM https://www.reddit.com/r/Batch/comments/qadj3w/print_screen_batch/Title Get a ScreenShot with Batch and Powershell
Set CaptureScreenFolder=C:\ScreenCapture\
If Not Exist "%CaptureScreenFolder%" MD "%CaptureScreenFolder%"
Set WaitTimeSeconds=5
:Loop
Call :ScreenShot
echo ScreenShot is taken on %Date% @ %Time% in Folder "%CaptureScreenFolder%"
Timeout /T %WaitTimeSeconds% /NoBreak>nul
Goto Loop
::----------------------------------------------------------------------------
:ScreenShot
Powershell ^
$Path = '%CaptureScreenFolder%';^
Add-Type -AssemblyName System.Windows.Forms;^
$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds;^
$image = New-Object System.Drawing.Bitmap($screen.Width, $screen.Height^);^
$graphic = [System.Drawing.Graphics]::FromImage($image^);^
$point = New-Object System.Drawing.Point(0,0^);^
$graphic.CopyFromScreen($point, $point, $image.Size^);^
$cursorBounds = New-Object System.Drawing.Rectangle([System.Windows.Forms.Cursor]::Position,[System.Windows.Forms.Cursor]::Current.Size^);^
[System.Windows.Forms.Cursors]::Default.Draw($graphic, $cursorBounds^);^
$FileName = $((Get-Date).ToString('dd-MM-yyyy_HH_mm_ss')+'.jpg');^
$FilePath = $Path+$FileName;^
$FormatJPEG = [System.Drawing.Imaging.ImageFormat]::jpeg;^
$image.Save($FilePath,$FormatJPEG^)
Exit /B
I am not sure what to try
Upvotes: 1
Views: 188