Sign in to follow this  
Followers 0
Efo74

Help Drawing in Autoit

10 posts in this topic

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 Help

Draw.au3


:rolleyes:

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Ohooops exceuse me ;)


:rolleyes:

Share this post


Link to post
Share on other sites

Func _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

Share this post


Link to post
Share on other sites

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):

Func _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

Share this post


Link to post
Share on other sites

Now used code box:

Func _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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Try this:

#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 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

You are the best . Thank you very much .... it works perfectly !!!!!!!!!!!!!!!!!! ;):)


:rolleyes:

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@UEZ

Your code save only empty white image for me (on WinXP)

You are the best . Thank you very much .... it works perfectly !!!!!!!!!!!!!!!!!! ;):)

@ Efo74

Which solution works for you?

Edited by Zedna

Share this post


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
Sign in to follow this  
Followers 0