Sign in to follow this  
Followers 0

how to Anti Alias

3 posts in this topic

Posted (edited)

Here is a code

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
_Main()
Func _Main()
Local $hGUI, $hGraphic
; Create GUI
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
_Curvature($hGUI,160,100,20,20,100,180,0x702E2EFE)
_DrawLine($hGui,160,100+(20/2),160,120+40,0x702E2EFE)
_Curvature($hGUI,160,160-(20/2),20,20,-100,180,0x702E2EFE)
; Draw arcs
;_GDIPlus_GraphicsDrawArc($hGraphic, 180, 100, 10, 10, 180, 360)
;_GDIPlus_GraphicsDrawArc($hGraphic, 160, 104, 30, 30, 160, -140)
;_GDIPlus_GraphicsDrawArc($hGraphic, 140, 80, 70, 70, 180, 360)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources

EndFunc   ;==>_Main
Func _DrawLine($Gui,$x1,$y1,$x2,$y2,$sChannel=0x80FFD700)
Local  $hGraphic, $hPen
; Draw line
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Gui)
$hPen = _GDIPlus_PenCreate ($sChannel)
If Not _GDIPlus_GraphicsDrawLine ($hGraphic, $x1,$y1,$x2,$y2, $hPen) Then ConsoleWrite('Error from GDI+:'&@error&@CRLF)
; Clean up resources
_GDIPlus_PenDispose ($hPen)
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_ShutDown ()
;Done.....
EndFunc   ;==>_Main
Func _Curvature($hGui, $iX, $iY, $iWidth, $iHeight, $fSweepAngle,$fStartAngle=180, $hPen = 0x80FFD700)
_GDIPlus_Startup()
Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hPen=_GDIPlus_PenCreate($hPen)
_GDIPlus_GraphicsDrawArc($hGraphic, $iX, $iY, $iWidth, $iHeight, $fStartAngle, $fSweepAngle , $hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc

I want to anti alias the Curves

I have already seen _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $iSmooth)

But it doesnt seem to do anything

Please guide me in the right direction

Thnx for your Time ;)

Edited by PhoenixXL

Share this post


Link to post
Share on other sites



Posted (edited)

Try this:

#include <guiconstantsex.au3>
#include <gdiplus.au3>
_GDIPlus_Startup()
Global $hGraphic, $hGUI
_Main()
Func _Main()
    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    _Curvature($hGUI,160,100,20,20,100,180,0x702E2EFE)
    _DrawLine($hGui,160,100+(20/2),160,120+40,0x702E2EFE)
    _Curvature($hGUI,160,160-(20/2),20,20,-100,180,0x702E2EFE)
    ; Draw arcs
    ;_GDIPlus_GraphicsDrawArc($hGraphic, 180, 100, 10, 10, 180, 360)
    ;_GDIPlus_GraphicsDrawArc($hGraphic, 160, 104, 30, 30, 160, -140)
    ;_GDIPlus_GraphicsDrawArc($hGraphic, 140, 80, 70, 70, 180, 360)
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    ; Clean up resources

    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_ShutDown ()
    Exit
EndFunc   ;==>_Main

Func _DrawLine($Gui,$x1,$y1,$x2,$y2,$sChannel=0x80FFD700)
    Local $hPen = _GDIPlus_PenCreate ($sChannel)
    If Not _GDIPlus_GraphicsDrawLine ($hGraphic, $x1,$y1,$x2,$y2, $hPen) Then ConsoleWrite('Error from GDI+:'&@error&@CRLF)
    _GDIPlus_PenDispose ($hPen)
EndFunc

Func _Curvature($hGui, $iX, $iY, $iWidth, $iHeight, $fSweepAngle,$fStartAngle=180, $hPen = 0x80FFD700)
    $hPen=_GDIPlus_PenCreate($hPen)
    _GDIPlus_GraphicsDrawArc($hGraphic, $iX, $iY, $iWidth, $iHeight, $fStartAngle, $fSweepAngle , $hPen)
    _GDIPlus_PenDispose ($hPen)
EndFunc

Btw, you don't need to start/shutdown GDI+ in each function. Create a global graphic handle and use it in you functions.

Or use this:

;coded by UEZ 2012
#include <GDIPlus.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()
$iW = 640
$iH = 480
$hgui = GUICreate("GDI+ draw rectangle with round corners", $iW, $iH)
GUISetBkColor(0x000020, $hgui)
GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$p = 150

Draw_RoundRect($hGraphic, $p, $p, $iW - $p, $p, $iH - 2 * $p) ;draw rectangle with round corners

GUISetOnEvent(-3, "_Exit")

While Sleep(100000)
WEnd

Func Draw_RoundRect($hGfx, $iX1, $iY1, $iX2, $iY2, $iDist, $iArcSize = 40, $iColor = 0xFFFFFFFF, $iPenSize = 2) ;coded by UEZ 2012
    Local $hPen = _GDIPlus_PenCreate($iColor, $iPenSize)
    _GDIPlus_GraphicsDrawLine($hGfx, $iX1, $iY1, $iX2 + 1, $iY2, $hPen) ;upper horizontal line
    _GDIPlus_GraphicsDrawArc($hGfx, $iX1 - $iArcSize / 2, $iY1, $iArcSize + 1, $iArcSize + 1, -90, -90, $hPen) ;left upper corner
    _GDIPlus_GraphicsDrawArc($hGfx, $iX2 - $iArcSize / 2, $iY2, $iArcSize, $iArcSize, 0, -90, $hPen) ;right upper corner
    _GDIPlus_GraphicsDrawArc($hGfx, $iX1 - $iArcSize / 2, $iY2 + $iDist - $iArcSize, $iArcSize, $iArcSize, 180, -90, $hPen) ;left bottom corner
    _GDIPlus_GraphicsDrawArc($hGfx, $iX2 - $iArcSize / 2, $iY2 + $iDist - $iArcSize, $iArcSize, $iArcSize, -270, -90, $hPen) ;right bottom corner
    _GDIPlus_GraphicsDrawLine($hGfx, $iX1 - $iArcSize / 2, $iY1 + $iArcSize / 2 - 1, $iX1 - $iArcSize / 2, $iY1 + $iDist - $iArcSize / 2 + 1, $hPen) ;left vertical line
    _GDIPlus_GraphicsDrawLine($hGfx, $iX2 + $iArcSize / 2, $iY2 + $iArcSize / 2 - 1, $iX2 + $iArcSize / 2, $iY2 + $iDist - $iArcSize / 2 + 1, $hPen) ;right vertical line
    _GDIPlus_GraphicsDrawLine($hGfx, $iX1 - 1, $iY1 + $iDist, $iX2 + 1, $iY2 + $iDist, $hPen) ;lower horizontal line
    _GDIPlus_PenDispose($hPen)
EndFunc

Func _Exit()
    GUIDelete()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Br,

UEZ

Edited by UEZ

Share this post


Link to post
Share on other sites

Posted

Thnx UEZ it worked ;)

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