Jump to content

string/text transparency with 'BrushSetSolidColor' alpha settings?


Burgs
 Share

Recommended Posts

Hello,

  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.

Regards

 

 

Link to comment
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>

Example()

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)
    GUISetState(@SW_SHOW)

    ; Draw a string
    _GDIPlus_Startup()
    $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)
        _GDIPlus_BrushDispose($hBrush)
    Next

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

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)

    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...