Jump to content
Sign in to follow this  

string/text transparency with 'BrushSetSolidColor' alpha settings?

Recommended Posts



  I'd like to set string/text opacity (transparency) using the _GDIPlus_BrushSetSolidColor command.  It seems that Alpha settings can be set using this command...however I'm not sure exactly how to use it the way I wish.

  For example if I'd like to set transparency on a 1-100 scale (1 = almost invisible, 100 = no transparency)...can this be done using this command...?  I know that using "FF" will set as not transparent ('100' in my example) ...but how do I input any other figure representing various opacity levels into this equation...?  Thus if I wanted the string text to appear 'half-transparent' (using a value of '50') can this be accomplished with this command?  Or perhaps I am missing something and there is another way to do it...?  I thank you in advance for any advice.




Share this post

Link to post
Share on other sites

Here is a modified _GDIPlus_GraphicsDrawStringEx() function example from AutoIt help file.  It shows different levels of transparency of text.

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


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

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetBkColor(0xFFDDDD) ; Hex colour format is 0xRRGGBB (0xRR for Red channel, 0xGG for Green channel, and 0xBB for Blue channel)chanels range from 0 to 0xFF or 255)

    ; Draw a string
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 18, 2)

    For $i = 0 To 100 Step 10
        $tLayout = _GDIPlus_RectFCreate(10, Int(2.6 * $i), 390, 50)
        ; Hex colour format is 0xAARRGGBB( when Alpha channel 0xAA = 0xFF the colour is 100% (fully) opaque. When 0xAA = 0x00 the colour is 100% fully transparent, invisible.)
        $hBrush = _GDIPlus_BrushCreateSolid("0x" & Hex(Int(255 * $i / 100), 2) & "0000FF")
        _GDIPlus_GraphicsDrawStringEx($hGraphic, "Hello world (" & 100 - $i & "% transparent)", $hFont, $tLayout, $hFormat, $hBrush)

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

    ; Clean up resources

EndFunc   ;==>Example


Share this post

Link to post
Share on other sites


  Thanks for that information...that seems helpful, I think I can get that to work for me, it seems to be what I'm looking for.  The post is much appreciated.    :)  



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