supersonic Posted February 11, 2016 Share Posted February 11, 2016 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 More sharing options...
InunoTaishou Posted February 11, 2016 Share Posted February 11, 2016 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. expandcollapse popup#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 More sharing options...
supersonic Posted February 12, 2016 Author Share Posted February 12, 2016 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. Link to comment Share on other sites More sharing options...
supersonic Posted February 12, 2016 Author Share Posted February 12, 2016 Maybe some can point me into right direction please: It rotates nicely but since using buffering '_GDIPlus_GraphicsSetSmoothingMode' has no effect!? Link to comment Share on other sites More sharing options...
UEZ Posted February 12, 2016 Share Posted February 12, 2016 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 More sharing options...
supersonic Posted February 12, 2016 Author Share Posted February 12, 2016 UEZ, can't believe it! Thank you very much. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now