Sign in to follow this  
Followers 0
gummybear

Image corrupted from _ScreenCapture_SaveImage

4 posts in this topic

#1 ·  Posted

I wrote a script to capture 4 times and save 4 different images as GIF. The code is as follows:

$capture = _ScreenCapture_Capture( "", 0, 0, $windowX, $windowY, False)
    _ScreenCapture_SaveImage($file_path & $serial & ".gif", $capture)

There are 4 instances of this capture command, using the same variable $capture with different $file_path.

I made the script go on an infinite loop until the user clicks Cancel, which will exit. The code lives within a While 1 loop. The user went through 165 loops, which created 660 images. Out of those images, 55 of them came out to be corrupted.

Opening it in windows photo viewer says "Windows Photo Viewer can't open this picture because the file appears to be damaged, corrupted, or too large." Opening it with Paint gives an invalid bitmap image error.

I did a search on this and surprising no results? Nobody EVER had an image corruption problem?

What can I do about this? The corruption seems to go like this:
- 1st capture: all pictures OK
- 2nd capture: 26 images corrupted
- 3rd capture: all images OK
- 4th capture: 29 images corrupted

I can create 4 different variables for $capture, like $capture1, $capture2, $capture3, etc. Reusing the $capture variable might be buggy in multiple loops. I'm also reusing other variables to check pixel color and other stuff. I'm concerned that since I'm having image capture problems, there might be problems with other variables too, after so many loops.

Other than that I'd have to SILENTLY validate that the images were captured and saved properly. Any ideas?

Share this post


Link to post
Share on other sites



#2 ·  Posted

I opened the corrupted GIF and normal GIF in Wordpad and it looks like the difference is there's something weird with the header.

A normal GIF starts with GIF89a as the header, whereas the corrupted one has a bunch of extra characters in front of that. This is probably what makes it corrupted and unreadable by the OS.

Share this post


Link to post
Share on other sites

#3 ·  Posted

Instead of the two commands to capture and save the screen, this one command will do the same.

_ScreenCapture_Capture($file_path & $serial & ".gif", 0, 0, $windowX, $windowY, False)

See _ScreenCapture_Capture() function in AutoIt help file.  Or, place cursor over _ScreenCapture_Capture in SciTE and press "F1".  This will open AutoIt help file at the _ScreenCapture_Capture function.


Also, a "Sleep(10)" or "Sleep(100)" is needed within the While loop.  This will give the processor enough time to process the command before starting the command again.     We want the command to start again after the previous command has finished.

Share this post


Link to post
Share on other sites

#4 ·  Posted

The captures are separated by several sleep commands and happen 10 seconds after each other.

The problem is iterating over the loops, the command is saving corrupted data to the image files.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0