Jump to content

AutoIt Windows Screenshooter v1.84 Build 2019-08-18


UEZ
 Share

Recommended Posts

6 hours ago, icadea said:

!>21:18:25 AutoIt3.exe ended.rc:-1073741819.

This error message means: Access Violation C0000005 - a Read or Write Access Violation occurs when the application attempts to read or write memory from a memory address that is invalid.

I tested it in my Win7 x64 VM and it works properly. I cannot reproduce this issue neither on Win10. :think:

Does the em occur everytime or on special moves? Same issue also with Windows Screenshooter?

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Uez,

Does the em occur everytime or on special moves? Same issue also with Windows Screenshooter? 

 

It occurs everytime on the separate code included for freehand select only.

No issue with Windows Screenshooter

 

Link to comment
Share on other sites

Ok, I got it. The code from 2011 is not x64 compatible when running it using Autoit x64.

This should fix the crash:

;code by UEZ 2011
#AutoIt3Wrapper_UseX64=y
#include <Array.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)



_GDIPlus_Startup()
$hHBitmap = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, False)
$hTexture = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
$hTextureBrush = _GDIPlus_TextureCreate($hTexture)
_WinAPI_DeleteObject($hHBitmap)

$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hTexture, 0, 0)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 2)

Global $dll = DllOpen("user32.dll")

GUISetOnEvent(-3, "_Exit")

$exitloop = False
$min_x = @DesktopWidth
$min_y = @DesktopHeight
$max_x = 0
$max_y = 0
$mo = MouseGetCursor()
Global $aPoints[2^20][2]
$p = 1
GUISetCursor(14, 1, $hGUI)
While Sleep(100)
    $mxo = MouseGetPos(0)
    $myo = MouseGetPos(1)
    While _IsPressed("01", $dll) * Sleep(10)
        $mx = MouseGetPos(0)
        $my = MouseGetPos(1)
        _GDIPlus_GraphicsDrawLine($hGraphic, $mx, $my, $mxo, $myo, $hPen)
        $mxo = $mx
        $myo = $my
        $aPoints[$p][0] = $mx
        $aPoints[$p][1] = $my
        $min_x = Min($min_x, $mx)
        $min_y = Min($min_y, $my)
        $max_x = Max($max_x, $mx)
        $max_y = Max($max_y, $my)
        $p += 1
        $exitloop = True
    WEnd
    If $exitloop Then ExitLoop
WEnd
GUISetCursor($mo, 1, $hGUI)

ReDim $aPoints[$p][2]
$aPoints[0][0] = $p - 1

_GDIPlus_GraphicsDispose($hGraphic)
$new_w =  $max_x - $min_x
$new_h =  $max_y - $min_y
$hBitmap_Hidden = _GDIPlus_BitmapCreateFromScan0(@DesktopWidth, @DesktopHeight)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap_Hidden)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)

_GDIPlus_GraphicsFillPolygon($hContext, $aPoints, $hTextureBrush)
$hBitmap_Capture = _GDIPlus_BitmapCloneArea($hBitmap_Hidden, $min_x, $min_y, $new_w, $new_h)
;~ _GDIPlus_ImageSaveToFile($hBitmap_Capture, "Testc.jpg")

GUISetOnEvent(-3, "")
GUIDelete($hGUI)
$hGUI = GUICreate("Freehand Screen Capture by UEZ 2011", $new_w, $new_h)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap_Capture, 0, 0)

GUISetOnEvent(-3, "_Exit")

_GDIPlus_BitmapDispose($hBitmap_Hidden)
_GDIPlus_BitmapDispose($hBitmap_Capture)
_GDIPlus_GraphicsDispose($hContext)

While Sleep(5000)
WEnd

Func Max($a, $b)
    If $a > $b Then Return $a
    Return $b
EndFunc

Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
EndFunc

Func _Exit()
    DllClose($dll)
    _GDIPlus_BrushDispose($hTextureBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hTexture)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    $aPoints = 0
    Exit
EndFunc

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Uez, thanks it works. The picture is shown in the gui.

 

Could you help on how can the picture be placed on clipboard?

 

I tried clipsetdata at the save file section and its not successful.

 

Thanks

 

found another link of yours.

https://www.autoitscript.com/forum/topic/121902-jpg-to-clipboard/?do=findComment&comment=846103

 

I have to rename _WinAPI_CopyImage to _WinAPI_CopyImageq for it to grab this one instead of default.

 

The default one hangs for 4seconds before showing the grab screen

 

Not sure how to dispose

_GDIPlus_ImageDispose($hImage)

as in the original script

 

The script below works. If you have any suggestion on how to make it better do advise in terms of less memory use or streamline. Thanks again

;code by UEZ 2011
#AutoIt3Wrapper_UseX64=y
#include <Array.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

#include <ClipBoard.au3>
#include <Constants.au3>
#include <GDIPlus.au3>


Opt("GUIOnEventMode", 1)



_GDIPlus_Startup()
$hHBitmap = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, False)
$hTexture = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
$hTextureBrush = _GDIPlus_TextureCreate($hTexture)
_WinAPI_DeleteObject($hHBitmap)

$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hTexture, 0, 0)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 2)

Global $dll = DllOpen("user32.dll")

GUISetOnEvent(-3, "_Exit")

$exitloop = False
$min_x = @DesktopWidth
$min_y = @DesktopHeight
$max_x = 0
$max_y = 0
$mo = MouseGetCursor()
Global $aPoints[2^20][2]
$p = 1
GUISetCursor(14, 1, $hGUI)
While Sleep(100)
    $mxo = MouseGetPos(0)
    $myo = MouseGetPos(1)
    While _IsPressed("01", $dll) * Sleep(10)
        $mx = MouseGetPos(0)
        $my = MouseGetPos(1)
        _GDIPlus_GraphicsDrawLine($hGraphic, $mx, $my, $mxo, $myo, $hPen)
        $mxo = $mx
        $myo = $my
        $aPoints[$p][0] = $mx
        $aPoints[$p][1] = $my
        $min_x = Min($min_x, $mx)
        $min_y = Min($min_y, $my)
        $max_x = Max($max_x, $mx)
        $max_y = Max($max_y, $my)
        $p += 1
        $exitloop = True
    WEnd
    If $exitloop Then ExitLoop
WEnd
GUISetCursor($mo, 1, $hGUI)

ReDim $aPoints[$p][2]
$aPoints[0][0] = $p - 1

_GDIPlus_GraphicsDispose($hGraphic)
$new_w =  $max_x - $min_x
$new_h =  $max_y - $min_y
$hBitmap_Hidden = _GDIPlus_BitmapCreateFromScan0(@DesktopWidth, @DesktopHeight)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap_Hidden)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)

_GDIPlus_GraphicsFillPolygon($hContext, $aPoints, $hTextureBrush)
$hBitmap_Capture = _GDIPlus_BitmapCloneArea($hBitmap_Hidden, $min_x, $min_y, $new_w, $new_h)
;~ _GDIPlus_ImageSaveToFile($hBitmap_Capture, "Testc.jpg")

$hBmpq = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Capture)
$hBitmapq = _WinAPI_CopyImageq($hBmpq, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)

_ClipBoard_Open(0)
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBitmapq, $CF_BITMAP)
_ClipBoard_Close()


;===============================================================================
;
; Function Name:   _WinAPI_CopyImage
; Description:: Copies an image, also makes GDIPlus-HBITMAP to GDI32-BITMAP
; Parameter(s): $hImg -> HBITMAP Object, GDI or GDIPlus
; Requirement(s):  WinAPI.au3
; Return Value(s): Succes: Handle to new Bitmap, Error: 0
; Author(s):    Prog@ndy
; http://www.autoitscript.com/forum/topic/70237-images-and-the-clipboard/page__p__514857
;===============================================================================
Func _WinAPI_CopyImageq($hImg, $uType = 0 ,$x = 0, $y = 0, $flags = 0)
    Local $aResult

    $aResult = DllCall("User32.dll", "hwnd", "CopyImage", "hwnd", $hImg, "UINT", $uType, "int", $x, "int", $y,"UINT", $flags)
;~  _WinAPI_Check("_WinAPI_CopyImage", ($aResult[0] = 0), 0, True)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_CopyIcon


GUISetOnEvent(-3, "")
GUIDelete($hGUI)
$hGUI = GUICreate("Freehand Screen Capture by UEZ 2011", $new_w, $new_h)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap_Capture, 0, 0)

GUISetOnEvent(-3, "_Exit")

_GDIPlus_BitmapDispose($hBitmap_Hidden)
_GDIPlus_BitmapDispose($hBitmap_Capture)
_GDIPlus_GraphicsDispose($hContext)

While Sleep(100)
WEnd

Func Max($a, $b)
    If $a > $b Then Return $a
    Return $b
EndFunc

Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
EndFunc

Func _Exit()
    DllClose($dll)
    _GDIPlus_BrushDispose($hTextureBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hTexture)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    $aPoints = 0
    Exit
EndFunc

 

Edited by icadea
spelling + code
Link to comment
Share on other sites

10 hours ago, icadea said:

Not sure how to dispose

You have to use _WinAPI_DeleteObject($hBmpq) as it is a GDI bitmap object.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 2 weeks later...
On 8/28/2019 at 11:34 AM, UEZ said:

You have to use _WinAPI_DeleteObject($hBmpq) as it is a GDI bitmap object.

Just out of curiosity, I ran the example with the built-in screen shot on my Windows 10 machine. It doesn't seem to work any longer. Am I right?

 

#include <ScreenCapture.au3>

Example()

Func Example()
    ; Capture full screen
    _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image1.jpg")

    ShellExecute(@MyDocumentsDir & "\GDIPlus_Image1.jpg")

    ; Capture region
    _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image2.jpg", 0, 0, 796, 596)

    ShellExecute(@MyDocumentsDir & "\GDIPlus_Image2.jpg")
EndFunc   ;==>Example

Thanks for any feedback.

Link to comment
Share on other sites

@coffeeturtle your examples runs properly on my Win10 machine with x86/x64. Both images are captured and opened without any issue.

Quote

...doesn't seem to work any longer...

Which version of AutoIt are you using?

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

3 hours ago, UEZ said:

@coffeeturtle your examples runs properly on my Win10 machine with x86/x64. Both images are captured and opened without any issue.

Which version of AutoIt are you using?

Hmmm.... good question. I am on 3.3.14.3.  Apparently, I am two minor versions behind as the current one is 3.3.14.5.  Looks like there are no script breaking changes between .3 and .5...I will update and retry today, UEZ.  Thanks.

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

×
×
  • Create New...