sandin Posted January 7, 2009 Share Posted January 7, 2009 This is modified example for create GDI plus graphic, with added option to make imaged of it, but it always turn out black, why? expandcollapse popup#include <GuiConstantsEx.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) $hWnd = WinGetHandle("GDI+") GUISetState() ; Draw a string _GDIPlus_Startup () $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd) $hBrush = _GDIPlus_BrushCreateSolid (0x7F00007F) $hFormat = _GDIPlus_StringFormatCreate () $hFamily = _GDIPlus_FontFamilyCreate ("Arial") $hFont = _GDIPlus_FontCreate ($hFamily, 12, 2) $tLayout = _GDIPlus_RectFCreate (140, 110, 100, 20) _GDIPlus_GraphicsDrawStringEx ($hGraphic, "Hello world", $hFont, $tLayout, $hFormat, $hBrush) Local $hbitimage = _GDIPlus_BitmapCreateFromGraphics(400, 300, $hGraphic) ;<--- crate image (black?) _GDIPlus_ImageSaveToFile($hbitimage, @DesktopDir & "\temp_image.bmp") _WinAPI_DeleteObject($hbitimage) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_FontDispose ($hFont) _GDIPlus_FontFamilyDispose ($hFamily) _GDIPlus_StringFormatDispose ($hFormat) _GDIPlus_BrushDispose ($hBrush) _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_Shutdown () EndFunc ;==>_Main Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
monoceres Posted January 7, 2009 Share Posted January 7, 2009 (edited) When you use _GDIPlus_BitmapCreateFromGraphics it doesn't mean that the content in the Graphics object are copied to the bitmap, the bitmap only gets the same format as the graphics object.Easiest way to accomplish what you want is to use a simple double buffering structure.I have posted a template here: http://www.autoitscript.com/forum/index.ph...mp;#entry617017And then use _GDIPlus_ImageSaveToFile($bitmap,"blah.png") Edited January 7, 2009 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
sandin Posted January 7, 2009 Author Share Posted January 7, 2009 (edited) thank you expandcollapse popup#include <GUIConstants.au3> #include <GDIplus.au3> HotKeySet("{F11}", "makeSS") Global Const $width=600 Global Const $height=400 GLobal $title="GDI+" ; Build your GUI here Opt("GUIOnEventMode",1) $hwnd=GUICreate($title,$width,$height) GUISetOnEvent($GUI_EVENT_CLOSE,"close") GUISetState() ; Load your GDI+ resources here: _GDIPlus_Startup() $graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd) $bitmap=_GDIPlus_BitmapCreateFromGraphics($width,$height,$graphics) $hBrush = _GDIPlus_BrushCreateSolid (0xFFFFFFFF);(0x2FB3E7FF) $hFormat = _GDIPlus_StringFormatCreate () $hFamily = _GDIPlus_FontFamilyCreate ("Arial") $hFont = _GDIPlus_FontCreate ($hFamily, 18, 2) $backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap) $txt = "something" Do _GDIPlus_GraphicsClear($backbuffer) $tLayout = _GDIPlus_RectFCreate (1/$width+50, 1/$height+5, 0, 0) _GDIPlus_GraphicsDrawStringEx ($backbuffer, $txt, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,0,0,$width,$height) Sleep(10) Until False Func makeSS() _GDIPlus_ImageSaveToFile($bitmap, @DesktopDir & "\blah.png") ConsoleWrite("SS made" & @CRLF) EndFunc Func close() _GDIPlus_GraphicsDispose($backbuffer) _GDIPlus_BitmapDispose($bitmap) _GDIPlus_GraphicsDispose($graphics) _GDIPlus_Shutdown() Exit EndFunc Edited January 7, 2009 by sandin Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll 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