ESPUser Posted October 4, 2020 Posted October 4, 2020 (edited) 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 October 4, 2020 by ESPUser
ESPUser Posted October 4, 2020 Author Posted October 4, 2020 (edited) 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! expandcollapse popup#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 October 4, 2020 by ESPUser
ESPUser Posted October 4, 2020 Author Posted October 4, 2020 I think i figured it out, but there may be better ways to do it expandcollapse popup#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
dmob Posted October 4, 2020 Posted October 4, 2020 8 hours ago, ESPUser said: ;this takes a lot of time. ReDim your array before your loop.
Nine Posted October 4, 2020 Posted October 4, 2020 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now