Jump to content

_ScreenCapture_Capture Problems


Recommended Posts

#include <ScreenCapture.au3>
$image = _ScreenCapture_Capture("C:\Users\aggixx\Desktop\test.tiff")

The above code does not work. It does not give an error, and exits the program 'normally' (console gives no errors) after about a 300 ms. So it seemed like it worked, but when I check my desktop, the file isn't there.

I used to have problems with the function crashing the program (In vista, an error message came up, not your normal console error), but that seems to have stopped now. I discovered that this line of code was causing the script to crash (found in _GDIPlus_ImageSaveToFileEx(), which is found in multiple places in the Screen Capture UDF):

$aResult = DllCall($ghGDIPDll, "int", "GdipSaveImageToFile", "hwnd", $hImage, "wstr", $sFileName, "ptr", $pGUID, "ptr", $pParams)

Of course, the crashes don't happen anymore, I just figured the info might be helpful in finding out what is causing it.

It'd probably be good for me too mention that the Capture function does not EVER work, at least with any combination of settings I've found (unless you leave it as a handle).

Any ideas?

Thanks ahead of time.

Link to comment
Share on other sites

#include <ScreenCapture.au3>
$image = _ScreenCapture_Capture("C:\Users\aggixx\Desktop\test.tiff")

The above code does not work. It does not give an error, and exits the program 'normally' (console gives no errors) after about a 300 ms. So it seemed like it worked, but when I check my desktop, the file isn't there.

I used to have problems with the function crashing the program (In vista, an error message came up, not your normal console error), but that seems to have stopped now. I discovered that this line of code was causing the script to crash (found in _GDIPlus_ImageSaveToFileEx(), which is found in multiple places in the Screen Capture UDF):

$aResult = DllCall($ghGDIPDll, "int", "GdipSaveImageToFile", "hwnd", $hImage, "wstr", $sFileName, "ptr", $pGUID, "ptr", $pParams)

Of course, the crashes don't happen anymore, I just figured the info might be helpful in finding out what is causing it.

It'd probably be good for me too mention that the Capture function does not EVER work, at least with any combination of settings I've found (unless you leave it as a handle).

Any ideas?

Thanks ahead of time.

Please share with us your code.
Link to comment
Share on other sites

Please share with us your code.

That's the strange thing, it's such a simple problem. I've tried using the function on many occasions, but it has never worked. So, I just wrote up a quick example, tested it (it didn't work), then posted it. It's the first codebox.

I guess I could search around for a more complex example if you wish.

Edit

Long story short, I was trying to write my own version of the CaptureScreen UDF, and it ended being pretty much the same. I had spliced this bit of code from an example I found on these forums and wrote into a UDF.

CODE

#include <GDIPlus.au3>

#include <File.au3>

Func _convert($in, $out, $format)

$timer = TimerInit ()

_GDIPlus_Startup()

ConsoleWrite("1"&@CRLF)

$image = _GDIPlus_ImageLoadFromFile($in)

ConsoleWrite("2"&@CRLF)

$create = _GDIPlus_ImageSaveToFileEx($image, $out, _GDIPlus_EncodersGetCLSID($format))

;$create = _GDIPlus_ImageSaveToFile($image, $out)

ConsoleWrite("4"&@CRLF)

_GDIPlus_Shutdown()

ConsoleWrite("5"&@CRLF)

$timerdiff = TimerDiff ($timer)

Return $create

EndFunc

_convert("C:\Users\aggixx\Desktop\record1\pic1.bmp", "C:\Users\aggixx\Desktop\record1\pic0.tif", "tif")

Now that I run the example, I find that the program crashes on the same line of code that I posted earlier.

Edited by aggixx
Link to comment
Share on other sites

Strangely, everything works fine for me. If you try to replace the "tif" to, for example, "jpg"?

Nope, still doesn't work. I figured it was probably just a problem with my computer, the question is: what?
Link to comment
Share on other sites

Nope, still doesn't work. I figured it was probably just a problem with my computer, the question is: what?

Perhaps the reason for the malfunction is in the CLSID, check which programs to view the images you have installed (ACDSee, etc.). This is just my opinion.
Link to comment
Share on other sites

Perhaps the reason for the malfunction is in the CLSID, check which programs to view the images you have installed (ACDSee, etc.). This is just my opinion.

Well, oddly enough, TIFs are opened with Photoshop, and TIFFs are opened with MSpaint. Is that what you meant?
Link to comment
Share on other sites

#include <ScreenCapture.au3>
$image = _ScreenCapture_Capture("C:\Users\aggixx\Desktop\test.tiff")

The above code does not work. It does not give an error, and exits the program 'normally' (console gives no errors) after about a 300 ms. So it seemed like it worked, but when I check my desktop, the file isn't there.

I used to have problems with the function crashing the program (In vista, an error message came up, not your normal console error), but that seems to have stopped now. I discovered that this line of code was causing the script to crash (found in _GDIPlus_ImageSaveToFileEx(), which is found in multiple places in the Screen Capture UDF):

$aResult = DllCall($ghGDIPDll, "int", "GdipSaveImageToFile", "hwnd", $hImage, "wstr", $sFileName, "ptr", $pGUID, "ptr", $pParams)

Of course, the crashes don't happen anymore, I just figured the info might be helpful in finding out what is causing it.

It'd probably be good for me too mention that the Capture function does not EVER work, at least with any combination of settings I've found (unless you leave it as a handle).

Any ideas?

Thanks ahead of time.

Well, I seem to have found an alternative to _ScreenCapture_Capture, but now I need a way to convert the BMP to a TIFF (I need it for OCR). Anyway to do it that doesn't involve GDI? Edited by aggixx
Link to comment
Share on other sites

Use FreeImage library.

Global Const $FIF_UNKNOWN = -1
Global Const $FIF_BMP = 0
Global Const $FIF_ICO = 1
Global Const $FIF_JPEG = 2
Global Const $FIF_JNG = 3
Global Const $FIF_KOALA = 4
Global Const $FIF_LBM = 5
Global Const $FIF_IFF = $FIF_LBM
Global Const $FIF_MNG = 6
Global Const $FIF_PBM = 7
Global Const $FIF_PBMRAW = 8
Global Const $FIF_PCD = 9
Global Const $FIF_PCX = 10
Global Const $FIF_PGM = 11
Global Const $FIF_PGMRAW = 12
Global Const $FIF_PNG = 13
Global Const $FIF_PPM = 14
Global Const $FIF_PPMRAW = 15
Global Const $FIF_RAS = 16
Global Const $FIF_TARGA = 17
Global Const $FIF_TIFF = 18
Global Const $FIF_WBMP = 19
Global Const $FIF_PSD = 20
Global Const $FIF_CUT = 21
Global Const $FIF_XBM = 22
Global Const $FIF_XPM = 23
Global Const $FIF_DDS = 24
Global Const $FIF_GIF = 25
Global Const $FIF_HDR = 26
Global Const $FIF_FAXG3 = 27
Global Const $FIF_SGI = 28

Global Const $Sourse = 'C:\WINDOWS\Web\Wallpaper\Ascent.jpg'
Global Const $Destination = 'C:\Ascent.tif'

$Dll = DllOpen('FreeImage.dll')

$hImage = DllCall($Dll, 'ptr', '_FreeImage_LoadU@12', 'int', $FIF_JPEG, 'wstr', $Sourse, 'int', 0)
DllCall($Dll, 'int', '_FreeImage_SaveU@16', 'int', $FIF_TIFF, 'ptr', $hImage[0], 'wstr', $Destination, 'int', 0)
DllCall($Dll, 'int', '_FreeImage_Unload@4', 'ptr', $hImage[0])

DllClose($Dll)
Link to comment
Share on other sites

Use FreeImage library.

Global Const $FIF_UNKNOWN = -1
Global Const $FIF_BMP = 0
Global Const $FIF_ICO = 1
Global Const $FIF_JPEG = 2
Global Const $FIF_JNG = 3
Global Const $FIF_KOALA = 4
Global Const $FIF_LBM = 5
Global Const $FIF_IFF = $FIF_LBM
Global Const $FIF_MNG = 6
Global Const $FIF_PBM = 7
Global Const $FIF_PBMRAW = 8
Global Const $FIF_PCD = 9
Global Const $FIF_PCX = 10
Global Const $FIF_PGM = 11
Global Const $FIF_PGMRAW = 12
Global Const $FIF_PNG = 13
Global Const $FIF_PPM = 14
Global Const $FIF_PPMRAW = 15
Global Const $FIF_RAS = 16
Global Const $FIF_TARGA = 17
Global Const $FIF_TIFF = 18
Global Const $FIF_WBMP = 19
Global Const $FIF_PSD = 20
Global Const $FIF_CUT = 21
Global Const $FIF_XBM = 22
Global Const $FIF_XPM = 23
Global Const $FIF_DDS = 24
Global Const $FIF_GIF = 25
Global Const $FIF_HDR = 26
Global Const $FIF_FAXG3 = 27
Global Const $FIF_SGI = 28

Global Const $Sourse = 'C:\WINDOWS\Web\Wallpaper\Ascent.jpg'
Global Const $Destination = 'C:\Ascent.tif'

$Dll = DllOpen('FreeImage.dll')

$hImage = DllCall($Dll, 'ptr', '_FreeImage_LoadU@12', 'int', $FIF_JPEG, 'wstr', $Sourse, 'int', 0)
DllCall($Dll, 'int', '_FreeImage_SaveU@16', 'int', $FIF_TIFF, 'ptr', $hImage[0], 'wstr', $Destination, 'int', 0)
DllCall($Dll, 'int', '_FreeImage_Unload@4', 'ptr', $hImage[0])

DllClose($Dll)
Looks great, but:

C:\Users\aggixx\Desktop\AU3 Scripts\test384.au3 (39) : ==> Subscript used with non-Array variable.:
DllCall($Dll, 'int', '_FreeImage_SaveU@16', 'int', $FIF_TIFF, 'ptr', $hImage[0], 'wstr', $Destination, 'int', 0)
DllCall($Dll, 'int', '_FreeImage_SaveU@16', 'int', $FIF_TIFF, 'ptr', $hImage^ ERROR
Link to comment
Share on other sites

Looks great, but:

C:\Users\aggixx\Desktop\AU3 Scripts\test384.au3 (39) : ==> Subscript used with non-Array variable.:
DllCall($Dll, 'int', '_FreeImage_SaveU@16', 'int', $FIF_TIFF, 'ptr', $hImage[0], 'wstr', $Destination, 'int', 0)
DllCall($Dll, 'int', '_FreeImage_SaveU@16', 'int', $FIF_TIFF, 'ptr', $hImage^ ERROR
Change to an existing picture (JPEG). This library is used by many programs. Actually read the documentation in a lot of interesting things. It also can be downloaded on the link that I gave you. This is a pretty powerful library.

$Sourse = 'C:\WINDOWS\Web\Wallpaper\Ascent.jpg'
Link to comment
Share on other sites

Change to an existing picture (JPEG). This library is used by many programs. Actually read the documentation in a lot of interesting things. It also can be downloaded on the link that I gave you. This is a pretty powerful library.

$Sourse = 'C:\WINDOWS\Web\Wallpaper\Ascent.jpg'
It gives me the same error even when the file exists.
Link to comment
Share on other sites

Link to comment
Share on other sites

If the file 'C:\WINDOWS\Web\Wallpaper\Ascent.jpg' exists and FreeImage.dll is in the same folder where your script, then everything should work! Nonses.

Well, that seems to make it work. But the problem is, the resulting file (tiff) is broken. It is not recognized by tesseract.exe or Photoshop.
Link to comment
Share on other sites

Well, that seems to make it work. But the problem is, the resulting file (tiff) is broken. It is not recognized by tesseract.exe or Photoshop.

Here are the errors it gives:

tesseract.log

Tesseract Open Source OCR Engine
name_to_image_type:Error:Unrecognized image type:captured.tiff
IMAGE::read_header:Error:Can't read this image type:captured.tiff
Tessedit:Error:Read of file failed:captured.tiff
Signal_exit 31 ABORT. LocCode: 3  AbortCode: 3

Adobe Photoshop CS3

Could not complete your request because it is not the right kind of document.
Link to comment
Share on other sites

Here are the errors it gives:

tesseract.log

Tesseract Open Source OCR Engine
name_to_image_type:Error:Unrecognized image type:captured.tiff
IMAGE::read_header:Error:Can't read this image type:captured.tiff
Tessedit:Error:Read of file failed:captured.tiff
Signal_exit 31 ABORT. LocCode: 3  AbortCode: 3

Adobe Photoshop CS3

Could not complete your request because it is not the right kind of document.
Give me your code (only relevant) and the image that you try to convert. I see.
Link to comment
Share on other sites

Give me your code (only relevant) and the image that you try to convert. I see.

Global Const $FIF_UNKNOWN = -1
Global Const $FIF_BMP = 0
Global Const $FIF_ICO = 1
Global Const $FIF_JPEG = 2
Global Const $FIF_JPG = $FIF_JPEG
Global Const $FIF_JNG = 3
Global Const $FIF_KOALA = 4
Global Const $FIF_LBM = 5
Global Const $FIF_IFF = $FIF_LBM
Global Const $FIF_MNG = 6
Global Const $FIF_PBM = 7
Global Const $FIF_PBMRAW = 8
Global Const $FIF_PCD = 9
Global Const $FIF_PCX = 10
Global Const $FIF_PGM = 11
Global Const $FIF_PGMRAW = 12
Global Const $FIF_PNG = 13
Global Const $FIF_PPM = 14
Global Const $FIF_PPMRAW = 15
Global Const $FIF_RAS = 16
Global Const $FIF_TARGA = 17
Global Const $FIF_TIFF = 18
Global Const $FIF_TIF = $FIF_TIFF
Global Const $FIF_WBMP = 19
Global Const $FIF_PSD = 20
Global Const $FIF_CUT = 21
Global Const $FIF_XBM = 22
Global Const $FIF_XPM = 23
Global Const $FIF_DDS = 24
Global Const $FIF_GIF = 25
Global Const $FIF_HDR = 26
Global Const $FIF_FAXG3 = 27
Global Const $FIF_SGI = 28

Func GetConvID($fileid)
    $retvar = "false"
    Switch $fileid
    Case "BMP"
        $retvar = 0
    Case "JPG" or "JPEG"
        $retvar = 2
    Case "PNG"
        $retvar = 13
    Case "TIF" or "TIFF"
        $retvar = 18
    Case "GIF"
        $retvar = 25
    EndSwitch
    Return $retvar
EndFunc

Global Const $Source = 'C:\WINDOWS\Web\Wallpaper\Ascent.jpg'
Global Const $Destination = 'C:\Ascent.tif'

$dll = DllOpen('FreeImage.dll')
;DllClose($Dll)

Func ConvertImg($in, $out)
    $inext = StringSplit( $in, ".", 1 )
    $inext = GetConvID($inext[$inext[0]])
    $outext = StringSplit( $out, ".", 1 )
    $outext = GetConvID($outext[$outext[0]])
    $hImage = DllCall($dll, 'ptr', '_FreeImage_LoadU@12', 'int', $inext, 'wstr', $in, 'int', 0)
    DllCall($Dll, 'int', '_FreeImage_SaveU@16', 'int', $outext, 'ptr', $hImage[0], 'wstr', $out, 'int', 0)
    DllCall($Dll, 'int', '_FreeImage_Unload@4', 'ptr', $hImage[0])
    Return FileExists( $out )
EndFunc

ConsoleWrite(ConvertImg("C:\Users\aggixx\Desktop\text.bmp","C:\Users\aggixx\Desktop\text.tiff"))

I modified the code a little, but you get the idea.

text.bmp

Edited by aggixx
Link to comment
Share on other sites

EDIT:

Func GetConvID($fileid)
    Switch $fileid
        Case "BMP"
            Return 0
        Case "JPG", "JPEG"
            Return 2
        Case "PNG"
            Return 13
        Case "TIF", "TIFF"
            Return 18
        Case "GIF"
            Return 25
        Case Else
            Return -1
    EndSwitch
EndFunc   ;==>GetConvID
Edited by Yashied
Link to comment
Share on other sites

EDIT:

Func GetConvID($fileid)
    Switch $fileid
        Case "BMP"
            Return 0
        Case "JPG", "JPEG"
            Return 2
        Case "PNG"
            Return 13
        Case "TIF", "TIFF"
            Return 18
        Case "GIF"
            Return 25
        Case Else
            Return -1
    EndSwitch
EndFunc   ;==>GetConvID
Well, it seems to be working relatively well now, but I'm still getting an error. It seems that the conversion is compressing the TIFF file, and Tesseract cannot support that.
Link to comment
Share on other sites

Well, it seems to be working relatively well now, but I'm still getting an error. It seems that the conversion is compressing the TIFF file, and Tesseract cannot support that.

$ret = DllCall($dll, 'int', '_FreeImage_SaveU@16', 'int', $outext, 'ptr', $hImage[0], 'wstr', $out, 'int', 0x0800)

aggixx, why did you not read the documentation, everything is written?

0x0800 - TIF without compression

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...