0

I would like to do a screen capture using AutoIt. My code:

#include <ScreenCapture.au3>
_ScreenCapture_Capture(@ScriptDir & "/test.jpg")

This doesn't work. And I know why. I tested what encoders I have:

#include <GDIPlus.au3>
$Encoders = _GDIPlus_Encoders()
MsgBox(0, "", UBound($Encoders))

The result is: 0. So why don't I have any encoders? And how can I get any?

user4157124
  • 2,809
  • 13
  • 27
  • 42
  • The encoders result is also zero on my system, but the screenshot gets saved, so your problem must be an other. (Note: you should use `\` as folder delimter, not `/` (although it works in most cases, the correct way on Windows is `\`) – Stephan Apr 03 '18 at 15:52
  • PS: The error code is -2. – letsCodeMyLife Apr 03 '18 at 17:26
  • what does `ConsoleWrite( _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN) & @CRLF)` return? Do you have a multi-monitor environment? – Stephan Apr 03 '18 at 17:49
  • how I get the $__SCREENCAPTURECONSTANT_SM_CYSCREEN variable? – letsCodeMyLife Apr 03 '18 at 20:29
  • `#include ` – Stephan Apr 03 '18 at 20:31
  • so i write this: `#include #include $h = ConsoleWrite( _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN) & @CRLF) MsgBox(0, "", $h)` and the MsgBox Displays 5. – letsCodeMyLife Apr 03 '18 at 20:41
  • and `MsgBox(0, "", _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN))` Displays 768 – letsCodeMyLife Apr 03 '18 at 20:54
  • Theory failed... `_ScreenCapture_Capture` returns @error -2, when the bottom value (786 in your case) is less than top value (zero in your case). Let me overthink it tomorrow - 11:15pm here... – Stephan Apr 03 '18 at 21:15
  • `_ScreenCapture_Capture` returns @error =-2 when `$iBottom > $iTop`. By default, Bottom is -1, which is translated to the screen height (the command I gave you yesterday to test). Default for Top is 0. So this really shouldn't happen. Try to give it the four optional screen values (like `_ScreenCapture_Capture(@ScriptDir & "/test.jpg", 0, 0, 1366, 768)` (if that's your screen resolution). Note: my `ScreenCapture.au3` has a date of 17-sep-2015 and a size of 10.923 bytes – Stephan Apr 04 '18 at 14:43
  • no its @error=2 and the screencapture function returns False. With your example function. – letsCodeMyLife Apr 04 '18 at 17:44
  • this `$screen = _ScreenCapture_Capture("") $gui = GUICreate("hello", @DesktopWidth / 2, @DesktopHeight / 2) GUISetState() _GDIPlus_Startup() $bmp = _GDIPlus_BitmapCreateFromHBITMAP($screen) $graphic = _GDIPlus_GraphicsCreateFromHWND($gui) _GDIPlus_GraphicsDrawImage($graphic, $bmp, 0, 0) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE` works. The Problem is to save the Bitmap as an Image file. – letsCodeMyLife Apr 04 '18 at 17:54
  • sorry, I'm out of ideas. – Stephan Apr 04 '18 at 18:03
  • The encoder result is "0" for me too, but like in Stephan's case, the screenshot gets saved. I would recommend asking this at the AutoIt forum. [link]https://www.autoitscript.com/forum/ – 1957classic Apr 04 '18 at 19:54
  • 1
    _GDIPlus_Encoders() will not return 0 if you run _GDIPlus_Startup() first – garbb Apr 05 '18 at 00:03
  • Try the example code from the help page for [_ScreenCapture_Capture()](https://www.autoitscript.com/autoit3/docs/libfunctions/_ScreenCapture_Capture.htm). Does this work? – garbb Apr 05 '18 at 00:13
  • no the example at the page also doesnt work – letsCodeMyLife Apr 05 '18 at 05:27

1 Answers1

0

This doesn't work. And I know why.

AutoIt v3.3.14.3 has a bug. Install latest version and it should work. Related.

user4157124
  • 2,809
  • 13
  • 27
  • 42