Sign in to follow this  
Followers 0
GrungeRocker

_GDIPlus_GraphicsDrawRect

5 posts in this topic

Hi.

I got a GUI with a Picture in it (drawn with GDI+).

Now I want the User to choose up to 32 areas, which should be marked with red rect's.

So I start up the function, that is showed below, when the image is clicked (Parameters are X and Y-Coordinates)

But it's really slow, so I wanted to ask if you know a better and faster solution.

Func _Zeichne_Rechteck($xs, $ys)
    $last_x = $xs
    $last_y = $ys
    _GDIPlus_GraphicsDrawRect($graphic, $xs, $ys, 1, 1)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_PRIMARYDOWN
                $rechtecke[0][0] = $rechtecke[0][0] + 1
                $TPoint = _WinAPI_GetMousePos(True, $Form1)
                $x = DllStructGetData($TPoint, "X")
                $y = DllStructGetData($TPoint, "Y")
                $rechtecke[$rechtecke[0][0]][0] = $xs
                $rechtecke[$rechtecke[0][0]][1] = $ys
                $rechtecke[$rechtecke[0][0]][2] = $x
                $rechtecke[$rechtecke[0][0]][3] = $y
                ExitLoop
        EndSwitch
        $TPoint = _WinAPI_GetMousePos(True, $Form1)
        $x = DllStructGetData($TPoint, "X")
        $y = DllStructGetData($TPoint, "Y")
        If $x>=16 And $x<=($width+16) And $y>=16 And $y<=($height+16) And $x <> $last_x And $y <> $last_y Then
            _GDIPlus_GraphicsDrawImageRect($graphic,$image,16,16,$width,$height)
        ;_Graph_Update()
            _GDIPlus_GraphicsDrawRect($graphic, $xs, $ys, $x-$xs, $y-$ys, $rot_pen)
            $last_x = $x
            $last_y = $y
        EndIf
    WEnd
EndFunc

Thanks

Grunge


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites



Hi.

I got a GUI with a Picture in it (drawn with GDI+).

Now I want the User to choose up to 32 areas, which should be marked with red rect's.

So I start up the function, that is showed below, when the image is clicked (Parameters are X and Y-Coordinates)

But it's really slow, so I wanted to ask if you know a better and faster solution.

Func _Zeichne_Rechteck($xs, $ys)
     $last_x = $xs
     $last_y = $ys
     _GDIPlus_GraphicsDrawRect($graphic, $xs, $ys, 1, 1)
     While 1
         $msg = GUIGetMsg()
         Switch $msg
             Case $GUI_EVENT_PRIMARYDOWN
                 $rechtecke[0][0] = $rechtecke[0][0] + 1
                 $TPoint = _WinAPI_GetMousePos(True, $Form1)
                 $x = DllStructGetData($TPoint, "X")
                 $y = DllStructGetData($TPoint, "Y")
                 $rechtecke[$rechtecke[0][0]][0] = $xs
                 $rechtecke[$rechtecke[0][0]][1] = $ys
                 $rechtecke[$rechtecke[0][0]][2] = $x
                 $rechtecke[$rechtecke[0][0]][3] = $y
                 ExitLoop
         EndSwitch
         $TPoint = _WinAPI_GetMousePos(True, $Form1)
         $x = DllStructGetData($TPoint, "X")
         $y = DllStructGetData($TPoint, "Y")
         If $x>=16 And $x<=($width+16) And $y>=16 And $y<=($height+16) And $x <> $last_x And $y <> $last_y Then
             _GDIPlus_GraphicsDrawImageRect($graphic,$image,16,16,$width,$height)
        ;_Graph_Update()
             _GDIPlus_GraphicsDrawRect($graphic, $xs, $ys, $x-$xs, $y-$ys, $rot_pen)
             $last_x = $x
             $last_y = $y
         EndIf
     WEnd
 EndFunc

Thanks

Grunge

Can you post sometrhing we can run? Then we can see the problem and try a change without having to write our own script first. W have no idea what $rechtecke[0][0] is for example.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>
#Include <Misc.au3>


_gdiplus_startup()

$Form1 = GUICreate("Tiff OCR", 801, 601, 212, 107)
;$Vorschau = GUICtrlCreateObj($oPreview, 16, 16, 465, 513)
$ListView = GUICtrlCreateListView("", 488, 32, 297, 369)
$Detail_Edit = GUICtrlCreateEdit("", 488, 424, 297, 105)
GUICtrlSetData(-1, "Details")
$Label1 = GUICtrlCreateLabel("Festgelegte Bereiche:", 488, 8, 107, 17)
$Picture_open = GUICtrlCreateButton("Neu", 48, 544, 121, 33, 0)
$Hinz_Button = GUICtrlCreateButton("Bereich hinzufügen", 200, 544, 121, 33, 0)
$Entf_Button = GUICtrlCreateButton("Bereich entfehrnen", 488, 544, 121, 33, 0)
$Speichern_Button = GUICtrlCreateButton("Speichern", 344, 544, 121, 33, 0)
$Exit_Button = GUICtrlCreateButton("Beenden", 672, 544, 121, 33, 0)
GUISetState(@SW_SHOW)

Global $graphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
Global $height, $width, $image
Global $rechtecke[33][4]
Global $rot_pen = _GDIPlus_PenCreate(0xFFFF0000)
$rechtecke[0][0] = 0


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown()
            Exit
        Case $Exit_Button
            _GDIPlus_Shutdown()
            Exit
        Case $GUI_EVENT_RESTORE
            _Graph_Update()
        Case $GUI_EVENT_PRIMARYUP
            _Graph_Update()
        Case $Picture_open
            $pfad = FileOpenDialog("Bild wählen", @ProgramFilesDir, "TIFF-Dateien (*.tif;*.tiff)",1 , "", $Form1)
            If Not @error Then
                _Show_img($pfad)
            EndIf
        Case $GUI_EVENT_PRIMARYDOWN
            $TPoint = _WinAPI_GetMousePos(True, $Form1)
            $x = DllStructGetData($TPoint, "X")
            $y = DllStructGetData($TPoint, "Y")
            If $x>=16 And $x<=($width+16) And $y>=16 And $y<=($height+16) Then
                _Zeichne_Rechteck($x, $y)
            EndIf
    EndSwitch
WEnd

Func _Show_img($path)
    $image = _gdiplus_imageloadfromfile($path)
    If @error Then
        MsgBox(0, "Error", "Das Bild konnte nicht geladen werden!")
    EndIf
    
    $pic_width = _GDIPlus_ImageGetWidth($image)
    $pic_height = _GDIPlus_ImageGetHeight($image)
    If $pic_height >= $pic_width Then
        $faktor = 513/$pic_height
    Else
        $faktor = 465/$pic_width
    EndIf

    $height = Floor($faktor*$pic_height)
    $width = Floor($faktor*$pic_width)

    _GDIPlus_GraphicsDrawImageRect($graphic,$image,16,16,$width,$height)
EndFunc

Func _Zeichne_Rechteck($xs, $ys)
    $last_x = $xs
    $last_y = $ys
    _GDIPlus_GraphicsDrawRect($graphic, $xs, $ys, 1, 1)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_PRIMARYDOWN
                $rechtecke[0][0] = $rechtecke[0][0] + 1
                $TPoint = _WinAPI_GetMousePos(True, $Form1)
                $x = DllStructGetData($TPoint, "X")
                $y = DllStructGetData($TPoint, "Y")
                $rechtecke[$rechtecke[0][0]][0] = $xs
                $rechtecke[$rechtecke[0][0]][1] = $ys
                $rechtecke[$rechtecke[0][0]][2] = $x
                $rechtecke[$rechtecke[0][0]][3] = $y
                ExitLoop
        EndSwitch
        $TPoint = _WinAPI_GetMousePos(True, $Form1)
        $x = DllStructGetData($TPoint, "X")
        $y = DllStructGetData($TPoint, "Y")
        If $x>=16 And $x<=($width+16) And $y>=16 And $y<=($height+16) And $x <> $last_x And $y <> $last_y Then
            _GDIPlus_GraphicsDrawImageRect($graphic,$image,16,16,$width,$height)
        ;_Graph_Update()
            _GDIPlus_GraphicsDrawRect($graphic, $xs, $ys, $x-$xs, $y-$ys, $rot_pen)
            $last_x = $x
            $last_y = $y
        EndIf
    WEnd
EndFunc

Func _Graph_Update()
    _GDIPlus_GraphicsDrawImageRect($graphic,$image,16,16,$width,$height)
    For $i = 0 To $rechtecke[0][0] Step 1
        _GDIPlus_GraphicsDrawRect($graphic, $rechtecke[$i][0], $rechtecke[$i][1], $rechtecke[$i][2]-$rechtecke[$i][0], $rechtecke[$i][3]-$rechtecke[$i][1], $rot_pen)
    Next
EndFunc

$rechtecke is an array for saving the rect's


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

I think this post by ProgAndy would be the nearest to what you want and it could easily be adapted to suit your script.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks.

I will give it a try tomorrow!

Good night


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

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