Sign in to follow this  
Followers 0
monoscout999

GDIPlus Basic help

3 posts in this topic

#1 ·  Posted (edited)

Hi forum i start to play whit GDI+ and i have a couple of issues

1. ¿wich way is the correct to dispose the brush?

¿this?

#include <GDIPlus.au3>
$GUI = Guicreate("Test GDI")
Guisetstate()
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
$size = WinGetClientSize($GUI)
$pos = Wingetpos($GUI)
Local $printcolor
for $x = $pos[0] + 6 to $size[0]
    for $y = $pos[1] + 22 to $size[1]
        $printcolor = _GDIPlus_BrushCreateSolid(0xff000000)
        _GDIPlus_GraphicsFillRect($hGraphics, $x, $y, 1, 1,$printcolor)
        _GDIplus_brushdispose($printcolor)
    Next
Next
sleep(5000)
_GDIPlus_Graphicsdispose($hGraphics)
_GDIPlus_Shutdown()

¿Or this?

#include <GDIPlus.au3>
$GUI = Guicreate("Test GDI")
Guisetstate()
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
$size = WinGetClientSize($GUI)
$pos = Wingetpos($GUI)
Local $printcolor
for $x = $pos[0] + 6 to $size[0]
    for $y = $pos[1] + 22 to $size[1]
        $printcolor = _GDIPlus_BrushCreateSolid(0xff000000)
        _GDIPlus_GraphicsFillRect($hGraphics, $x, $y, 1, 1,$printcolor)
    Next
Next
sleep(5000)
_GDIplus_brushdispose($printcolor)
_GDIPlus_Graphicsdispose($hGraphics)
_GDIPlus_Shutdown()

2. ¿Wich way is the best to print on screen a bitmap from a variable reading?

the variable contains randoms 0 and 1

0 = black

1 = White

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>

Global $texto
$xlargo = 350
$ylargo = 350
$GUI = GUICreate("Mi GUI con imagen", -1, 500, -1, -1)
GUISetBkColor(0x225599)
$boton1 = GUICtrlCreateButton("Abrir Archivo", 25, 400, 175, 30)
$boton2 = GUICtrlCreateButton("generar binario", 200, 400, 175, 30)
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
GUISetState(@SW_SHOW, $GUI)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose($hGraphics)
            _GDIPlus_Shutdown()
            Exit
        Case $boton1
            $filename = FileOpenDialog("Eliga el archivo binario", "", "(*.txt)")
            $fileopen = FileOpen($filename)
            $texto = FileRead($fileopen)
            x0()
        Case $boton2
            _Generaraleatorio()
    EndSwitch
WEnd
Func x0()

    Local $x = 25
    Local $y = 25
    Local $uno = StringSplit($texto, "")
    Local $contar = UBound($uno) - 1

    For $pc = 1 To $contar
        Select
            Case $uno[$pc] = 0
                $color = _GDIPlus_BrushCreateSolid(0x55000000)
            Case $uno[$pc] = 1
                $color = _GDIPlus_BrushCreateSolid(0x55FFFFFF)
        EndSelect
        _GDIPlus_GraphicsFillRect($hGraphics, $x, $y, 1, 1,$color)
        _GDIPlus_BrushDispose($color)
        $x += 1
        If $x = $xlargo + 25 Then
            $x = 25
            $y += 1
            If $y = $ylargo + 25 Then ExitLoop
        EndIf
    Next
EndFunc   ;==>x0
Func _Generaraleatorio()
    Local $p = 0
;~  ProgressOn("Progreso", "Generando imagen aleatorea...", $p & "/ 10000")
    Do
        $texto = $texto & Random(0, 1, 1)
        $p += 1
;~      ProgressSet($p * 0.0008, $p & "/ 122500")
    Until $p = 12250
    Sleep(500)
;~  ProgressOff()
    x0()
EndFunc   ;==>_Generaraleatorio

PD: press the right button to make it work, wait 6 or 7 seconds until the variable loads with randoms 0 and 1. :huh2:

the example is a little rusty because is made by me a couple of months ago

3. ¿Is necesary have a GUI where display the bitmap or i can print on the screen whitout it?

If someone take the time to answer i will apreciate

Edited by monoscout999

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

1) creating a brush in a loop will cause a memory leak if you don't dispose it afterwards. In your example you fill the graphic screen with black pixels. I would do it this way:

#include <GDIPlus.au3>
$GUI = Guicreate("Test GDI")
Guisetstate()
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
$size = WinGetClientSize($GUI)
$pos = Wingetpos($GUI)
Local $printcolor  = _GDIPlus_BrushCreateSolid(0xff000000)
for $y = 0 to $size[1]
    for $x = 0 to $size[0]
        _GDIPlus_GraphicsFillRect($hGraphics, $x, $y, 1, 1,$printcolor)
    Next
Next
sleep(5000)
 _GDIplus_brushdispose($printcolor)
_GDIPlus_Graphicsdispose($hGraphics)
_GDIPlus_Shutdown()

The first x and y coordinate is not $pos[0] respectively $pos[1], it is 0,0!

2) to change the color of a brush use _GDIPlus_BrushSetSolidColor() instead of creating a brush everytime.

3) you can print to screen directly but after a refresh it will be erased - a GUI with a screen makes more sense.

Look here: http://www.autoitscript.com/forum/index.php?showtopic=87200. There are plenty of examples.

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

@UEZ

:huh2:

i dont have words... i´m shocked anout the GDI+ examples of that link... algorithmes and more algorithmes

I think i gonna start whit some ball bouncing the sides of the GUI

Later i will try acceleration algorithmes.

I will ask here on the forum if i need any help...

Thanks a lot

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