Jump to content

Recommended Posts

Hello,

is there a simple example of how to draw on the screen (with a mouse or with my finger when using a touch display) similar to a painting program?

I would like to make a script where the user can sign with his name.

I am a bit lost, do not know where to start.

Edited by ESPUser
Link to post
Share on other sites

after some more searching i found this Post:

I changed the code a bit to work on current AutoIt and to fit my needs.

I am still lokking for three things:

  • How can i change the background to white?
  • How can i change the pen (make it a bit thicker)
  • How can i save the bmp (preferred as jpg) when the signature is done?

If someone can hint an this, that would be great, thanks in advance!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <WinAPISysWin.au3>

Opt("TrayIconDebug", 1)

$Paint = GUICreate("Signature", 500, 350, -1, -1, -1, -1)
_GDIPlus_Startup()

$hGraphic_GUI = _GDIPlus_GraphicsCreateFromHWND($Paint)

$hBuffer_Bmp = _GDIPlus_BitmapCreateFromGraphics(500, 350, $hGraphic_GUI)
$hGraphic_Buffer_Bmp = _GDIPlus_ImageGetGraphicsContext($hBuffer_Bmp)

Global $af_Points[1][2] = [[0]]

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUISetState()

While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE

            ;release the resources
            _GDIPlus_GraphicsDispose($hGraphic_Buffer_Bmp)
            _GDIPlus_ImageDispose($hBuffer_Bmp)

            _GDIPlus_GraphicsDispose($hGraphic_GUI)
            _GDIPlus_Shutdown()

            Exit

        Case $GUI_EVENT_PRIMARYDOWN

            ;paint the Buffer-Img
            Paint_Buffer()

    Case $GUI_EVENT_SECONDARYDOWN

        ;erase the stuff
        _GDIPlus_GraphicsClear($hGraphic_Buffer_Bmp, 0xFFF0F0F0)

        ;dont wait for the processing of the GUI
        _WinAPI_PostMessage($Paint, $WM_PAINT, 0, 0)

    EndSwitch
WEnd

Func Paint_Buffer()

    Do

        $cPos = GUIGetCursorInfo()
        If IsArray($cPos) = 0 Then ExitLoop

        $af_Points[0][0] += 1

        ;search for _ArrayAddEx to speed up at this point, written by Guinness.
        If UBound($af_Points) - 1 < $af_Points[0][0] + 1 Then ReDim $af_Points[$af_Points[0][0] + 1000][2]  ;this takes a lot of time.

        $af_Points[$af_Points[0][0]][0] = $cPos[0] + 1 / 2
        $af_Points[$af_Points[0][0]][1] = $cPos[1] + 1 / 2

        ;tbd: add pen object
        _GDIPlus_GraphicsDrawCurve2($hGraphic_Buffer_Bmp, $af_Points,0.01)

        ;dont wait for the processing of the GUI
        _WinAPI_PostMessage($Paint, $WM_PAINT, 0, 0)

        ;pause
        Sleep(18)   ;to reduce the CPU usage a little.

    Until $cPos[2] = 0

    ;reset the variable.
    ReDim $af_Points[1][2]
    $af_Points[0][0] = 0

EndFunc   ;==>Paint_Buffer

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)

    ;paint the buffer image on the GUI.
    _GDIPlus_GraphicsDrawImage($hGraphic_GUI, $hBuffer_Bmp, 0, 0)

EndFunc   ;==>WM_PAINT

 

Edited by ESPUser
Link to post
Share on other sites

I think i figured it out, but there may be better ways to do it

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <SendMessage.au3>
#include <WinAPISysWin.au3>

Opt("TrayIconDebug", 1)

$Paint = GUICreate("Signature", 500, 350, -1, -1, -1, -1)
_GDIPlus_Startup()

$hGraphic_GUI = _GDIPlus_GraphicsCreateFromHWND($Paint)

$hBuffer_Bmp = _GDIPlus_BitmapCreateFromGraphics(500, 350, $hGraphic_GUI)
$hGraphic_Buffer_Bmp = _GDIPlus_ImageGetGraphicsContext($hBuffer_Bmp)
_GDIPlus_GraphicsClear($hGraphic_Buffer_Bmp, 0xFFFFFFFF )

Global $af_Points[1][2] = [[0]]

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUISetState()

While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE

            ;release the resources
            _GDIPlus_GraphicsDispose($hGraphic_Buffer_Bmp)
            _GDIPlus_ImageDispose($hBuffer_Bmp)

            _GDIPlus_GraphicsDispose($hGraphic_GUI)
            _GDIPlus_Shutdown()

            Exit

        Case $GUI_EVENT_PRIMARYDOWN

            ;paint the Buffer-Img
            Paint_Buffer()

        Case $GUI_EVENT_SECONDARYDOWN
        ;save to file
        _GDIPlus_ImageSaveToFile($hBuffer_Bmp, @ScriptDir & "\GDIPlus_Image.jpg")
        ;erase the stuff
        _GDIPlus_GraphicsClear($hGraphic_Buffer_Bmp, 0xFFFFFFFF )

        ;do not wait for the processing of the GUI
        _WinAPI_PostMessage($Paint, $WM_PAINT, 0, 0)

    EndSwitch
WEnd

Func Paint_Buffer()

    Do

        $cPos = GUIGetCursorInfo()
        If IsArray($cPos) = 0 Then ExitLoop

        $af_Points[0][0] += 1

        ;search for _ArrayAddEx to speed up at this point, written by Guinness.
        If UBound($af_Points) - 1 < $af_Points[0][0] + 1 Then ReDim $af_Points[$af_Points[0][0] + 1000][2]  ;this takes a lot of time.

        $af_Points[$af_Points[0][0]][0] = $cPos[0] + 1 / 2
        $af_Points[$af_Points[0][0]][1] = $cPos[1] + 1 / 2


        $g_hPen = _GDIPlus_PenCreate(0xFF000000 , 3)
        _GDIPlus_GraphicsDrawCurve2($hGraphic_Buffer_Bmp, $af_Points,0.01,$g_hPen)

        ;do not wait for the processing of the GUI
        _WinAPI_PostMessage($Paint, $WM_PAINT, 0, 0)

        ;pause
        Sleep(18)   ;to reduce the CPU usage a little.

    Until $cPos[2] = 0

    ;reset the variable.
    ReDim $af_Points[1][2]
    $af_Points[0][0] = 0

EndFunc   ;==>Paint_Buffer

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)

    ;paint the buffer image on the GUI.
    _GDIPlus_GraphicsDrawImage($hGraphic_GUI, $hBuffer_Bmp, 0, 0)

EndFunc   ;==>WM_PAINT

 

Link to post
Share on other sites

There is no point of ReDim $af_Points[1][2] after loop, just create your array at 2000 for example, if it needs to be larger than your code will increase the array.  Just set the counter to 0 after loop, that is enough.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...