resize screen image

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
rblack
Pro Scripter
Posts: 87
Joined: Sat Dec 22, 2007 12:39 pm

resize screen image

Post by rblack » Fri Jan 08, 2010 9:34 pm

Hello,

i have a lot of complicated scripts and some of them are crashing from time to time, i want to create an function, that will take a SNAPSHOT of the entire SCREEN , save it in c:\photos\macros as {script_name}_{date}.bmp , then will send a smaller version jpg (600x480 or even smaller) to my email [email protected]

I want this to be done entirely with macro sheduller 11 (without any other software), is this possible?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jan 08, 2010 10:16 pm


rblack
Pro Scripter
Posts: 87
Joined: Sat Dec 22, 2007 12:39 pm

Post by rblack » Sat Jan 09, 2010 2:09 pm

yes i have tried that, but with no sucess - i want this resized picture to be saved on disc, but it doesnt work with those handles,

Code: Select all

ScreenCapture>0,0,1024,768,%DESKTOP_DIR%\screen.bmp
LibFunc>Gdi32,StretchBlt,SBres,%DESKTOP_DIR%\screen2.jpg,0,0,640,480,%DESKTOP_DIR%\screen.bmp,0,0,1024,768,13369376

wish that would work :P

Can you help me please ?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sun Jan 10, 2010 5:07 am

Here's a script that takes a screen shot then reduces the screen shot image and writes the screen shot and the reduced images to files that can then be attached to a mail message. Note that the directory structure C:\Photos\Macros\ must exist for the files to be created. This uses screen captures so there's a bit of screen activity. Its possible there is a way to reduce one image file directly to another image file but I don't know how to do that. Maybe someone else knows how?

This version writes BMP files, All you need to do to write JPG files is change the extension in the file name. (More Macro Scheduler magic)

Read the comments, ask questions if anything is unclear. Hope this is more helpful.

Code: Select all

//Set the X and Y size for the email image
Let>ResizeX=640
Let>ResizeY=480

//Acquire the name of the running macro or executable
//If run form the Macro Scheduler menu this will be msched
//In which case the desired name may need to be hard coded
Separate>%command_line%,\,name
Let>filename=name_%name_count%
Separate>filename,.,vFilename

//Get date and time info for filename datestamp
Sec>ss
Min>mn
Hour>hh
Day>dd
Month>mm
Year>yy

//Need the screen resolution
GetScreenRes>ScrX,ScrY

//Set names of files
Let>ReSizeFilename=C:\Photos\Macros\%vFilename_1%_%yy%%mm%%dd%%hh%%mn%%ss%_%ResizeX%_%ResizeY%.bmp
Let>Filename=C:\Photos\Macros\%vFilename_1%_%yy%%mm%%dd%%hh%%mn%%ss%_%scrX%_%scrY%.bmp

//Capture the screen and save to %Filename%
ScreenCapture>0,0,ScrX,ScrY,%Filename%

//Set both Device Context Handles to the screen. (saves having to deal with dialogs)
LibFunc>user32,GetDC,HDC1,0
LibFunc>user32,GetDC,HDC3,0

//Use the StretchBlt API function to reduce and display the screen image
LibFunc>Gdi32,StretchBlt,SBres,HDC3,0,0,ResizeX,ResizeY,HDC1,0,0,scrX,scrY,13369376

//Capture and save the reduced image
ScreenCapture>0,0,ResizeX,ResizeY,%ReSizeFilename%

//Clean up the clutter from the screen
//This could be eliminated by creating a dialog and displaying the reduced image on the dialog
SetFocus>Program Manager
Press F5
Press LWinKey
Send>d
Release LWinKey
Wait>0.5
Press LWinKey
Send>d
Release LWinKey

//Add code for emailing the reduced size image

rblack
Pro Scripter
Posts: 87
Joined: Sat Dec 22, 2007 12:39 pm

Post by rblack » Sun Jan 10, 2010 12:51 pm

oh yeah it works! Thats what i wanted to do! Thank you JRL! Only the script name is always mshed, but its no problem to hardcode that :)

Thank you!!!

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sun Jan 10, 2010 6:48 pm

I thought of a cleaner way to clean up the screen. Here's the improved script.

Code: Select all

//Set the X and Y size for the email image
Let>ResizeX=640
Let>ResizeY=480

//Acquire the name of the running macro or executable
//If run form the Macro Scheduler menu this will be msched
//In which case the desired name may need to be hard coded
Separate>%command_line%,\,name
Let>filename=name_%name_count%
Separate>filename,.,vFilename

//Get date and time info for filename datestamp
Sec>ss
Min>mn
Hour>hh
Day>dd
Month>mm
Year>yy

//Need the screen resolution
GetScreenRes>ScrX,ScrY

//Set names of files
Let>ReSizeFilename=C:\Photos\Macros\%vFilename_1%_%yy%%mm%%dd%%hh%%mn%%ss%_%ResizeX%_%ResizeY%.jpg
Let>Filename=C:\Photos\Macros\%vFilename_1%_%yy%%mm%%dd%%hh%%mn%%ss%_%scrX%_%scrY%.jpg

//Capture the screen and save to %Filename%
ScreenCapture>0,0,ScrX,ScrY,%Filename%

//Set both Device Context Handles to the screen. (saves having to deal with dialogs)
LibFunc>user32,GetDC,HDC1,0
LibFunc>user32,GetDC,HDC3,0

//Use the StretchBlt API function to reduce and display the screen image
LibFunc>Gdi32,StretchBlt,SBres,HDC3,0,0,ResizeX,ResizeY,HDC1,0,0,scrX,scrY,13369376

//Capture and save the reduced image
ScreenCapture>0,0,ResizeX,ResizeY,%ReSizeFilename%

//Clean up the clutter from the screen
Dialog>ScreenEraser
   Width=%scrX%
   Height=%scrY%
EndDialog>ScreenEraser
Show>ScreenEraser
CloseDialog>ScreenEraser

//Add code for emailing the reduced size image

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Tue Jan 12, 2010 12:45 pm

Nice example JR.

To resize the image to 50% e.g. replace the the first 3 lines of JR's last script

Code: Select all

//Set the X and Y size for the email image
Let>ResizeX=640
Let>ResizeY=480
With this one...

Code: Select all

//Set the X and Y size for the email image
///Get Screen Resolution
GetScreenRes>X,Y
// Set percentage to resize image to. (0.50=50%)
let>PERCENT=0.50
//Calculate percentage of screen resolution
Let>ResizeX=%X%*%PERCENT%
Let>ResizeY=%Y%*%PERCENT%
//Round result
Let>ResizeX={round(%ResizeX%)}
Let>ResizeY={round(%ResizeY%)}

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts