Sign in to follow this  
Followers 0
nomadicwolf

GDI+ Buffers

3 posts in this topic

#1 ·  Posted (edited)

Hello All; can someone explain and/or help me with GDI+ buffering:

If I write GDI+ text direct to a graphic it looks nice:
(this code is the _GDIPlus_GraphicsDrawString example:)

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

Example()

Func Example()
    Local $hGUI, $hGraphic

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState(@SW_SHOW)

    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    _GDIPlus_GraphicsDrawString($hGraphic, "Hello world", 140, 110)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

Now, If I draw it to a Buffer first, as per the _GDIPlus_BitmapCreateFromGraphics code example, the text looks like crap:

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

Example()

Func Example()
    Local $hGUI, $hGraphic

    ; Create GUI
    $g_hGUI = GUICreate("GDI+", 400, 300)
    GUISetState(@SW_SHOW)

    ; Draw a string
    _GDIPlus_Startup()


    ;create buffer (from _GDIPlus_BitmapCreateFromGraphics example:)
    $g_hGfx = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
    $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics(400, 300, $g_hGfx) ;create a Bitmap object based on a graphics object
    $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) ;get the graphics context of the image to draw on image


    _GDIPlus_GraphicsDrawString($g_hGfxCtxt, "Hello world", 140, 110)
    _GDIPlus_GraphicsDrawImage($g_hGfx, $g_hBitmap, 0, 0)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

But, doing some experimenting, I found that if I add the following line before the drawString, that sets the bitmap to white and alpha channel to 100% opaque, then the text looks good again, but then it defeats my purpose as the text is suppose to be draw on top of other graphics.

_GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000  + 0xFFFFFF )


So, 1. what is going on here with the drawing of the text, i.e. was does it look like crap in the buffer, and

2. how do I write "nice" text to a buffer to put it ontop of something else?.

Thank you.
 

P.S. I just atatched pics of what the text looks like on my system in case it is system dependant.

post-86894-0-32752700-1412865002_thumb.j

post-86894-0-77213900-1412865012_thumb.j

Edited by nomadicwolf

Share this post


Link to post
Share on other sites



1. use _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, 4) and _GDIPlus_GraphicsSetTextRenderingHint($g_hGfxCtxt, 4)

2. use an empty bitmap (_GDIPlus_BitmapCreateFromScan0), draw the string to that bitmap and copy this bitmap to the main graphics

3. dispose all GDI+ resources ;)

Br,

UEZ


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

Share this post


Link to post
Share on other sites

Thanks UEZ, that helped a lot.

Notes to others that come across this:

1. _GDIPlus_GraphicsSetSmoothingMode also has smoothing modes 3,4 & 5 that are not listed in the online or downloaded help files but are listed in GDIPlusConstants.au3

2. I found that the smoothing mode made no difference to text rendering and I ended up not using it.

3. _GDIPlus_GraphicsSetTextRenderingHint DID make quite a difference on the rendering of the text. I ended up using mode 3 or $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT

4. The explanations of these modes for both functions are truncated in the help files but are full in GDIPlusConstants.au3

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  
Followers 0