Unable to Restore Image

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Unable to Restore Image

Post by armsys » Fri Oct 16, 2015 12:35 am

The following script can't restore the original capture.
The restored .bmp becomes readable. Why? Please help. Thanks.

Code: Select all

// Clean up all previously leftover test files
DeleteFile>C:\Temp\WS1_Image.txt
DeleteFile>C:\Temp\Test.bmp

// Capture the entire screen
GetScreenRes>Width,Height
ScreenCapture>0,0,Width,Height,C:\Temp\Test.bmp

// Store the screen capture as text file on disk
ReadFile>C:\Temp\Test.bmp,ImageData
Base64>ImageData,Encode,b64data
Let>WLN_NOCRLF=1
WriteLn>c:\Temp\WS1_Image.txt,result,b64data

// Retrieve the previously stored text file
ReadFile>C:\Temp\WS1_Image.txt,Binary
Base64>Binary,DECODE,B64Data
WriteLn>C:\Temp\Image.bmp,result,B64Data

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Unable to Restore Image

Post by armsys » Fri Oct 16, 2015 5:23 am

Images created by CyberCitizen's script are corrupt too.

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Unable to Restore Image

Post by hagchr » Fri Oct 16, 2015 7:31 am

Hi, seems to be problem with c:\temp. If I write/read eg using c:\users\...\desktop\ then your code works fine.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Unable to Restore Image

Post by armsys » Fri Oct 16, 2015 8:05 am

Hi hagchr,
hagchr wrote:Hi, seems to be problem with c:\temp. If I write/read eg using c:\users\...\desktop\ then your code works fine.
Thanks for taking time to test my mysterious code.
Nope, here I test on C:\Users\...\Desktop per your suggestion, but the resultant image, namely, Image.bmp, remains corrupt!
Last edited by armsys on Fri Oct 16, 2015 8:21 am, edited 1 time in total.

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Unable to Restore Image

Post by hagchr » Fri Oct 16, 2015 8:17 am

If I step through the code then ScreenCapture> to c:\temp\ gives the code "2: Unable to save image to specified file". Permission problem?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Unable to Restore Image

Post by armsys » Fri Oct 16, 2015 8:29 am

My SCREENCAP_RESULT returns perfectly 0 (zero).
But the resultant Image.bmp remains corrupt.

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Unable to Restore Image

Post by hagchr » Fri Oct 16, 2015 8:41 am

Really strange, I get a 2 when I step through the same way. Currently running Win10 and MS with Admin Priv.

[img]C:\Users\Christer\Desktop\screen.bmp[/img]

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Unable to Restore Image

Post by hagchr » Fri Oct 16, 2015 8:42 am

Ops! How do you insert an image?

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Unable to Restore Image

Post by hagchr » Fri Oct 16, 2015 8:49 am

I need to use C:\Windows\Temp\ then I also get result=0

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Unable to Restore Image

Post by hagchr » Fri Oct 16, 2015 8:55 am

This works fine on my machine (just added Windows to the path and also writing out the file to the desktop):

Code: Select all

// Clean up all previously leftover test files
DeleteFile>C:\Windows\Temp\WS1_Image.txt
DeleteFile>C:\Windows\Temp\Test.bmp

// Capture the entire screen
GetScreenRes>Width,Height
ScreenCapture>0,0,Width,Height,C:\Windows\Temp\Test.bmp

// Store the screen capture as text file on disk
ReadFile>C:\Windows\Temp\Test.bmp,ImageData
Base64>ImageData,Encode,b64data
Let>WLN_NOCRLF=1
WriteLn>C:\Windows\Temp\WS1_Image.txt,result,b64data

// Retrieve the previously stored text file
ReadFile>C:\Windows\Temp\WS1_Image.txt,Binary
Base64>Binary,DECODE,B64Data
WriteLn>C:\Windows\Temp\Image.bmp,result,B64Data

WriteLn>C:\users\christer\desktop\Image.bmp,result,B64Data

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Unable to Restore Image

Post by armsys » Fri Oct 16, 2015 8:57 am

Attach your screen capture by clicking 'Upload attachment' tab below.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Unable to Restore Image

Post by armsys » Fri Oct 16, 2015 9:04 am

I run your code and encounter the same corrupt image problem.
But the original 9MB image created by ScreenCapture, namely, Test.bmp, is perfectly fine.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Unable to Restore Image

Post by armsys » Fri Oct 16, 2015 9:29 am

Not sure if the Base64> imposes a size limit to the source.
I notice the file size of the original and resultant image files are different. Why?

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Unable to Restore Image

Post by hagchr » Fri Oct 16, 2015 10:03 am

Hi, I added one ScreenCapture> to the desktop. Both looks fine and with exact same size. Strange that it does not work on your machine.
screen.png

Code: Select all

// Clean up all previously leftover test files
DeleteFile>C:\Windows\Temp\WS1_Image.txt
DeleteFile>C:\Windows\Temp\Test.bmp

// Capture the entire screen
GetScreenRes>Width,Height
ScreenCapture>0,0,Width,Height,C:\Windows\Temp\Test.bmp
ScreenCapture>0,0,Width,Height,C:\users\christer\desktop\Test.bmp


// Store the screen capture as text file on disk
ReadFile>C:\Windows\Temp\Test.bmp,ImageData
Base64>ImageData,Encode,b64data
Let>WLN_NOCRLF=1
WriteLn>C:\Windows\Temp\WS1_Image.txt,result,b64data

// Retrieve the previously stored text file
ReadFile>C:\Windows\Temp\WS1_Image.txt,Binary
Base64>Binary,DECODE,B64Data
WriteLn>C:\Windows\Temp\Image.bmp,result,B64Data

WriteLn>C:\users\christer\desktop\Image.bmp,result,B64Data

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Unable to Restore Image

Post by armsys » Fri Oct 16, 2015 10:06 am

What's the version of your Macro Scheduler?
Mine is 14.2.02 - November 2014

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