Jump to content

Recommended Posts

Posted

Hi,

I'm encountering an inconsistency when using GDI+ in AutoIt with paths.

 

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

Global $hGUI, $hGraphics, $hBrush, $hPen1, $hPen2, $hPath1, $hPath2, $hPath3, $hPath4

_Main()

Func _Main()
    _GDIPlus_Startup()

    $hGUI = GUICreate("", 200, 200)
    GUISetState(@SW_SHOW, $hGUI)

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hPen1 = _GDIPlus_PenCreate(0xFFFF0000, 1)
    $hPen2 = _GDIPlus_PenCreate(0xFF0000FF, 1)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
    $hPath1 = _GDIPlus_PathCreate()
    $hPath2 = _GDIPlus_PathCreate()
    $hPath3 = _GDIPlus_PathCreate()
    $hPath4 = _GDIPlus_PathCreate()


    Local $base = 10
    Local $outletOffset = 2

    Local $aPoints1[8][2] = [ _
            [7, 0], _
            [$base + 0,     $base + 0], _
            [$base + 100,   $base + 0], _
            [$base + 100,   $base + 20], _
            [$base + 57,    $base + 20], _
            [$base + 50,    $base + 27], _
            [$base + 43,    $base + 20], _
            [$base + 0,     $base + 20] _
    ]
    _GDIPlus_PathAddPolygon($hPath1, $aPoints1)

    Local $offset = 4
    Local $aPoints2[8][2]
    $aPoints2[0][0] = 7
    $aPoints2[1][0] = $aPoints1[1][0] - $outletOffset
    $aPoints2[1][1] = $aPoints1[1][1] - $outletOffset
    $aPoints2[2][0] = $aPoints1[2][0] + $outletOffset
    $aPoints2[2][1] = $aPoints1[2][1] - $outletOffset
    $aPoints2[3][0] = $aPoints1[3][0] + $outletOffset
    $aPoints2[3][1] = $aPoints1[3][1] + $outletOffset
    $aPoints2[4][0] = $aPoints1[4][0]
    $aPoints2[4][1] = $aPoints1[4][1] + $outletOffset
    $aPoints2[5][0] = $aPoints1[5][0]
    $aPoints2[5][1] = $aPoints1[5][1] + $outletOffset
    $aPoints2[6][0] = $aPoints1[6][0]
    $aPoints2[6][1] = $aPoints1[6][1] + $outletOffset
    $aPoints2[7][0] = $aPoints1[7][0] - $outletOffset
    $aPoints2[7][1] = $aPoints1[7][1] + $outletOffset

    Local $aPoints3 = duplicateWithOffset($aPoints1, 0, 40)
    Local $aPoints4 = duplicateWithOffset($aPoints2, 0, 40)

    ; Construction du path
    _GDIPlus_PathAddPolygon($hPath2, $aPoints2)
    _GDIPlus_PathAddPolygon($hPath3, $aPoints3)
    _GDIPlus_PathAddPolygon($hPath4, $aPoints4)

    ; Dessin initial
    _Draw()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $GUI_EVENT_RESTORE, $GUI_EVENT_RESIZED
                _Draw()
        EndSwitch
    WEnd

    _GDIPlus_PathDispose($hPath1)
    _GDIPlus_PathDispose($hPath2)
    _GDIPlus_PathDispose($hPath3)
    _GDIPlus_PathDispose($hPath4)
    _GDIPlus_PenDispose($hPen1)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
EndFunc

Func duplicateWithOffset($aPoints, $offsetX, $offsetY)
    Local $aPoints2 = $aPoints
    For $i = 1 To $aPoints2[0][0]
        $aPoints2[$i][0] += $offsetX
        $aPoints2[$i][1] += $offsetY
    Next
    Return $aPoints2
EndFunc


Func _Draw()
    _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF)
    _GDIPlus_GraphicsFillPath($hGraphics, $hPath1, $hBrush)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath2, $hPen1)
    _GDIPlus_GraphicsFillPath($hGraphics, $hPath3, $hBrush)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath3, $hPen2)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath4, $hPen1)
EndFunc

Result :

image.png.b1698e553eff3498ece3a93e30883476.png

Context

  • I have a base path (path1)
  • I generate a second path (path2) generated from path1 using a constant offset

Case 1 (top image)

  • I use _GDIPlus_GraphicsFillPath with path1
  • Then _GDIPlus_GraphicsDrawPath with path2

Result:
There is a visible gap, which is noticeably larger on the bottom and right sides.

Case 2 (bottom image)

  • I use _GDIPlus_GraphicsFillPath with path1
  • Then _GDIPlus_GraphicsDrawPath with the same path (path1)
  • Then _GDIPlus_GraphicsDrawPath with path2

Result:
This shows that the filled path (FillPath) does not align perfectly with the outline produced by DrawPath, even when using the exact same geometry.

Problem

It seems that:

_GDIPlus_GraphicsFillPath and _GDIPlus_GraphicsDrawPath do not render the same path in the same way.

This leads to visible offsets and inconsistent borders when combining fill + drawing offseted paths.

Question

  • Is this expected behavior in GDI+?
  • Is it related to pen alignment, pixel snapping, or anti-aliasing?
  • What is the correct way to ensure perfect alignment between fill and stroke?

Thanks!

 

 

 

 

_GUIRegisterMsg (Register more than 1 time the same Msg), _Resize_Window (GUICtrlSetResizing for children windows), _GUICtrlSetOnHover (Link a function when mouse go on, left, clic down, clic up, on a control), _InputHeure (Create an input for hour contain), _GUICtrlCalendar (Make a complete calendar), _GUICtrlCreateGraphic3D (Create a 3D graph), _ArrayEx.au3 (Array management), _GUIXViewEx.au3 (List/Tree View management).
Posted (edited)
5 hours ago, TommyDDR said:

Question

  • Is this expected behavior in GDI+?

Yes because you add

_GDIPlus_PathAddPolygon($hPath3, $aPoints3)

which is not equal to the first figure above.

Try

$hPen2 = _GDIPlus_PenCreate(0xFF000000, 1)

and you will see an additional border which doesn't exist in 1st figure.

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

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
×
×
  • Create New...