Jump to content
Sign in to follow this  

GDIplus question

Recommended Posts


This is modified example for create GDI plus graphic, with added option to make imaged of it, but it always turn out black, why?

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)


Func _Main()
    Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    $hWnd = WinGetHandle("GDI+")

    ; 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")
    ; Loop until user exits
    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

Share this post

Link to post
Share on other sites

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;#entry617017

And then use _GDIPlus_ImageSaveToFile($bitmap,"blah.png")


Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post

Link to post
Share on other sites

thank you :)

#include <GUIConstants.au3>
#include <GDIplus.au3>

HotKeySet("{F11}", "makeSS")

Global Const $width=600
Global Const $height=400
GLobal $title="GDI+"

; Build your GUI here

; Load your GDI+ resources here:
$hBrush = _GDIPlus_BrushCreateSolid (0xFFFFFFFF);(0x2FB3E7FF)
$hFormat = _GDIPlus_StringFormatCreate ()
$hFamily = _GDIPlus_FontFamilyCreate ("Arial")
$hFont = _GDIPlus_FontCreate ($hFamily, 18, 2)
$txt = "something"
    $tLayout = _GDIPlus_RectFCreate (1/$width+50, 1/$height+5, 0, 0)
    _GDIPlus_GraphicsDrawStringEx ($backbuffer, $txt, $hFont, $tLayout, $hFormat, $hBrush)
Until False

Func makeSS()
    _GDIPlus_ImageSaveToFile($bitmap, @DesktopDir & "\blah.png")
    ConsoleWrite("SS made" & @CRLF)

Func close()
Edited by sandin

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.