Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

InunoTaishou,

thank you, the buffer seems to do the trick! And pointing my to Google is not rude! :) I'll never get what's behind GDI to get things together :( This is not my first attempt trying to understand GDI.

 

 

Posted

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

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...