Jump to content

GDI - Rotate _GDIPlus_GraphicsDrawArc flickers


Recommended Posts

Hi!

I'm trying to rotate graphics (pen / arc) created with GDI. It rotates but with strong flickering and it slows down... I know there is the ability to use matrix rotation but I can't get it working. Here's a reproducer (from AutoIt help):

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

Example()

Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ;$iBGColor format RRGGBB

    Local $hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ;create a test GUI
    GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
    GUISetState(@SW_SHOW)

    ;create buffered graphics frame set for smoother gfx object movements
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
    Local $hPen = _GDIPlus_PenCreate(0xFFFF8080, 32) ;color format AARRGGBB (hex)

    Local $iTmp = 0
    _GDIPlus_GraphicsDrawArc($hGraphics, 100.5, 100.5, 400.25, 400.25, $iTmp, 270.5, $hPen)

    Do
        $iTmp = (($iTmp = 360) ? (0) : ($iTmp + 1))
        _GDIPlus_GraphicsClear($hGraphics, 0xFF000000 + $iBgColor) ;clear bitmap for repaint
        _GDIPlus_GraphicsDrawArc($hGraphics, 100.5, 100.5, 400.25, 400.25, $iTmp, 270.5, $hPen)
        Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup GDI+ resources
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

I'm not good at GDI :-( So any help help is greatly appreciated.

Link to comment
Share on other sites

Cool design, looks like it could be an interesting loading animation.

Not to sound rude but did you bother googling: GDI+ Flicker? Flickering is bound to happen because that's how GDI works. It clears the graphic object then draws what you want. To get around that you use a buffer.

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

Example()

Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ;$iBGColor format RRGGBB

    Local $hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ;create a test GUI
    GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
    GUISetState(@SW_SHOW)

    ;create buffered graphics frame set for smoother gfx object movements
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    Local $hWnd_bitmap = _GDIPlus_BitmapCreateFromGraphics(615, 395, $hGraphics)
    Local $hWnd_gdi_buffer = _GDIPlus_ImageGetGraphicsContext($hWnd_bitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
    Local $hPen = _GDIPlus_PenCreate(0xFFFF8080, 32) ;color format AARRGGBB (hex)

    Local $iTmp = 0
    _GDIPlus_GraphicsDrawArc($hWnd_gdi_buffer, 100.5, 100.5, 400.25, 400.25, $iTmp, 270.5, $hPen)

    Do
        $iTmp = (($iTmp = 360) ? (0) : ($iTmp + 1))
        _GDIPlus_GraphicsClear($hWnd_gdi_buffer, 0xFF000000 + $iBgColor) ;clear bitmap for repaint
        _GDIPlus_GraphicsDrawArc($hWnd_gdi_buffer, 100.5, 100.5, 400.25, 400.25, $iTmp, 270.5, $hPen)
        _GDIPlus_GraphicsDrawImage($hGraphics, $hWnd_bitmap, 0, 0)
        Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup GDI+ resources
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hWnd_bitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

My variables are underscore case so you can see what I added and changed how your drawing works.

Link to comment
Share on other sites

When you use back bufferiing then you have to set the smoothing also to the back buffer gfx handle!

 

_GDIPlus_GraphicsSetSmoothingMode($hWnd_gdi_buffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY)

 

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...