Efo74 Posted June 17, 2012 Share Posted June 17, 2012 Can Someone help me in this script ?I modyfy a script made from - Author: name22 (www.autoit.de), and it seems to work, but now i Can't save my work drawing. Excuse for errors in the code but it is only a Test. The Purpose of the program is make an handwritten sign and save to jpg file.Thank you for HelpDraw.au3 :rolleyes: Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2012 Moderators Share Posted June 17, 2012 Efo74,Please pay attention to where you post - this section is for "Examples" as it explains clearly at the top. I will move the thread to the "General Help" section. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Efo74 Posted June 17, 2012 Author Share Posted June 17, 2012 Ohooops exceuse me :rolleyes: Link to comment Share on other sites More sharing options...
Zedna Posted June 17, 2012 Share Posted June 17, 2012 expandcollapse popupFunc _SaveImage() _GDIPlus_Save_to_Image(@DesktopDir & "File001.jpg", $frm_Disegno) EndFunc ; #FUNCTION# ============================================================================= ; Name.............: _GDIPlus_Save_to_Image ; Description ...: INTERNAL FUNCTION - save drawnelements in GUI to file ; Syntax...........: _GDIPlus_Save_to_Image($file, $hWnd) ; Parameters ...: $file - filename ; $hWnd - handle to GUI ; Author .........: ptrex, ProgAndy, UEZ ; ========================================================================================= Func _GDIPlus_Save_to_Image($file, $hWnd) Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $size, $err, $sCLSID, $ext, $fExt If $file <> "" Or $hWnd <> "" Then $size = WinGetClientSize($hWnd) $w = $size[0] $h = $size[1] $hDC = _WinAPI_GetDC($hWnd) $memDC = _WinAPI_CreateCompatibleDC($hDC) $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h) _WinAPI_SelectObject ($memDC, $memBmp) _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, 0x00CC0020) ; 0x00CC0020 = $SRCCOPY $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp) $ext = "png,bmp,jpg,tif,gif" $fExt = StringRight($file, 3) If Not StringInStr($ext, $fExt) Then $CLSID = "PNG" $file &= ".png" Else $CLSID = $fExt EndIf $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID) If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1 _GDIPlus_ImageDispose ($hImage) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($memDC) _WinAPI_DeleteObject ($memBmp) If $err Then Return SetError(2, 0, 0) Return SetError(0, 0, 0) Else Return SetError(1, 0, 0) EndIf EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted June 17, 2012 Share Posted June 17, 2012 My previous post is totally corrupted due to forum upgrade. I can't edit that post. So here is my previous code (I hiope it will be OK now): expandcollapse popupFunc _SaveImage() _GDIPlus_Save_to_Image(@DesktopDir & "File001.jpg", $frm_Disegno) EndFunc ; #FUNCTION# ============================================================================= ; Name.............: _GDIPlus_Save_to_Image ; Description ...: INTERNAL FUNCTION - save drawnelements in GUI to file ; Syntax...........: _GDIPlus_Save_to_Image($file, $hWnd) ; Parameters ...: $file - filename ; $hWnd - handle to GUI ; Author .........: ptrex, ProgAndy, UEZ ; ========================================================================================= Func _GDIPlus_Save_to_Image($file, $hWnd) Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $size, $err, $sCLSID, $ext, $fExt If $file <> "" Or $hWnd <> "" Then $size = WinGetClientSize($hWnd) $w = $size[0] $h = $size[1] $hDC = _WinAPI_GetDC($hWnd) $memDC = _WinAPI_CreateCompatibleDC($hDC) $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h) _WinAPI_SelectObject ($memDC, $memBmp) _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, 0x00CC0020) ; 0x00CC0020 = $SRCCOPY $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp) $ext = "png,bmp,jpg,tif,gif" $fExt = StringRight($file, 3) If Not StringInStr($ext, $fExt) Then $CLSID = "PNG" $file &= ".png" Else $CLSID = $fExt EndIf $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID) If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1 _GDIPlus_ImageDispose ($hImage) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($memDC) _WinAPI_DeleteObject ($memBmp) If $err Then Return SetError(2, 0, 0) Return SetError(0, 0, 0) Else Return SetError(1, 0, 0) EndIf EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted June 17, 2012 Share Posted June 17, 2012 Now used code box: expandcollapse popupFunc _SaveImage() _GDIPlus_Save_to_Image(@DesktopDir & "File001.jpg", $frm_Disegno) EndFunc ; #FUNCTION# ============================================================================= ; Name.............: _GDIPlus_Save_to_Image ; Description ...: INTERNAL FUNCTION - save drawnelements in GUI to file ; Syntax...........: _GDIPlus_Save_to_Image($file, $hWnd) ; Parameters ...: $file - filename ; $hWnd - handle to GUI ; Author .........: ptrex, ProgAndy, UEZ ; ========================================================================================= Func _GDIPlus_Save_to_Image($file, $hWnd) Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $size, $err, $sCLSID, $ext, $fExt If $file <> "" Or $hWnd <> "" Then $size = WinGetClientSize($hWnd) $w = $size[0] $h = $size[1] $hDC = _WinAPI_GetDC($hWnd) $memDC = _WinAPI_CreateCompatibleDC($hDC) $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h) _WinAPI_SelectObject ($memDC, $memBmp) _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, 0x00CC0020) ; 0x00CC0020 = $SRCCOPY $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp) $ext = "png,bmp,jpg,tif,gif" $fExt = StringRight($file, 3) If Not StringInStr($ext, $fExt) Then $CLSID = "PNG" $file &= ".png" Else $CLSID = $fExt EndIf $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID) If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1 _GDIPlus_ImageDispose ($hImage) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($memDC) _WinAPI_DeleteObject ($memBmp) If $err Then Return SetError(2, 0, 0) Return SetError(0, 0, 0) Else Return SetError(1, 0, 0) EndIf EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
UEZ Posted June 17, 2012 Share Posted June 17, 2012 (edited) Try this: expandcollapse popup#include <Misc.au3> #include <WinAPI.au3> #include <GDIPlus.au3> #include <GUIConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> $vU32Dll = DllOpen("User32.dll") $iGraphicX = 100 $iGraphicY = 5 $iGraphicWidth = 395 $iGraphicHeight = 390 $Spessore_Penna = 2 $frm_Disegno = GUICreate("Mouse Draw", 500,400) $idPic = GUICtrlCreatePic("", $iGraphicX, $iGraphicY, $iGraphicWidth, $iGraphicHeight) GUICtrlSetState(-1, $GUI_DISABLE) $hPic = GUICtrlGetHandle($idPic) $cButton_Reset = GUICtrlCreateButton("Reset", 15, 190, 60, 25) $cButton_Save = GUICtrlCreateButton("Save", 15, 220, 60, 25) Global $Array_xy[10000][2] GUISetState() _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hPic) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGraphicWidth, $iGraphicHeight, $hGraphic) $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) $hPen_Main = _GDIPlus_PenCreate(0xFF000000, $Spessore_Penna) $aOldPos = "none" $punti = 0 _ResetImage() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then _Exit() EndIf If $msg = $cButton_Reset Then _ResetImage() If $msg = $cButton_Save Then _SaveImage() $InfoCursore = GUIGetCursorInfo($frm_Disegno) If $InfoCursore[4] = $idPic And _IsPressed("01", $vU32Dll) Then ; Se tasto Mouse Sinistro Premuto e la pressione avviene nel rettangolo dell'area definita di disegno If $aOldPos[0] - $iGraphicX <> $InfoCursore[0] - $iGraphicX Or $aOldPos[1] - $iGraphicY <> $InfoCursore[1] - $iGraphicY Then $punti +=1 $Array_xy[0][0] = $punti $Array_xy[$punti][0]=$InfoCursore[0] - $iGraphicX $Array_xy[$punti][1]=$InfoCursore[1] - $iGraphicY _GDIPlus_GraphicsDrawCurve($hBuffer, $Array_xy, $hPen_Main) _GDIPlus_GraphicsDrawRect($hBuffer, 0, 0, $iGraphicWidth -1, $iGraphicHeight - 1) ;Rettangolo Bordo Disegno _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iGraphicWidth, $iGraphicHeight) EndIf Else $aOldPos = "none" $punti = 0 $Array_xy[0][0] = $punti EndIf $aOldPos = $InfoCursore Sleep(10) WEnd ;****************************************************************************************************************************** Func _ResetImage() ;****************************************************************************************************************************** _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF) _GDIPlus_GraphicsDrawRect($hBuffer, 0, 0, $iGraphicWidth - 1, $iGraphicHeight - 1) ;Rettangolo Bordo Disegno _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iGraphicWidth, $iGraphicHeight) ;disegna rettangolo bianco di disegno EndFunc ;****************************************************************************************************************************** Func _SaveImage() ;****************************************************************************************************************************** _GDIPlus_ImageSaveToFile($hBitmap, @DesktopDir & "\File001.jpg") EndFunc ;****************************************************************************************************************************** Func _Exit() ;****************************************************************************************************************************** _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hBuffer) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_PenDispose($hPen_Main) _GDIPlus_Shutdown() GUIDelete() Exit EndFunc Br, UEZ Edited June 17, 2012 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 More sharing options...
Efo74 Posted June 17, 2012 Author Share Posted June 17, 2012 You are the best . Thank you very much .... it works perfectly !!!!!!!!!!!!!!!!!! :rolleyes: Link to comment Share on other sites More sharing options...
Zedna Posted June 17, 2012 Share Posted June 17, 2012 (edited) @UEZYour code save only empty white image for me (on WinXP)You are the best . Thank you very much .... it works perfectly !!!!!!!!!!!!!!!!!! @ Efo74Which solution works for you? Edited June 17, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted June 17, 2012 Share Posted June 17, 2012 @ Efo74Your script has ISSUE - after minimize/restore of GUI painted stuff dissapear.You must implement WM_PAINT to fix that.Search this forum for examples for that. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
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