Jump to content

Outline in letters using GDI


 Share

Recommended Posts

I would like to know if it is possible to outline the letters that appear in a transparent window or with a black background using GDI, would it be contouring around the letters of cdg files, would it be possible to add contours to these letters?

6XrWKxKf_t.jpg

Link to comment
Share on other sites

In a basic programming language you would do something like this:

Set color to red. Draw the text around the text position 9 (or more, depending on how big the outline should be) times. Set the color to yellow and draw the text at the text position.

something like:

 

Txt$="Test text"
tx=10
ty=10

color $ff,0,0
for x=-1 to 1
    for y=-1 to 1
        Text tx+x,ty+y,Txt$
    next
next

Color $ff,$ff,0

Text tx,ty,txt$

 

I modified the Autoit GDI+ help example and here is the result:

#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)
    $tx=30
    $ty=30
    $txt="Hello World"
    for $x=-1 to 1
        for $y=-1 to 1
        _GDIPlus_GraphicsDrawString($hGraphic, $txt, $tx+$x, $ty+$y,Default,20,Default,0xFFFF0000)
        Next
    Next

    _GDIPlus_GraphicsDrawString($hGraphic, $txt, $tx, $ty, Default, 20, Default, 0xFFFFFF00)

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

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

 

 

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

@Dan_555 I think I didn't explain it well but I need to outline the letters in an external window and possibly there's no way to do this, for it to work I think the letters would have to be created with GDI as well.

Link to comment
Share on other sites

Something like that?

#include <GDIPlus.au3>

$hMain = GUICreate('GDI Outline', 800, 600)
GUISetState(@SW_SHOW, $hMain)

DrawOutlineText($hMain, 'Some text', 200, 200, 300, 100, 0xFFFF8000, 0xFFC0C0C0)

Do
    Sleep(10)
Until GUIGetMsg() = -3

Func DrawOutlineText($hGUI, $sText, $iX, $iY, $iWidth, $iHeight, $iTextColor, $iOutlineColor, $sFont='Arial', $iSize = 50)
    _GDIPlus_Startup()
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
    Local $hFontFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hPath = _GDIPlus_PathCreate()
    Local $tLayout = _GDIPlus_RectFCreate($iX, $iY, $iWidth, $iHeight)
    Local $hPen = _GDIPlus_PenCreate($iTextColor, 2)
    Local $hBrush = _GDIPlus_BrushCreateSolid($iOutlineColor)
    _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFontFamily, 0, $iSize)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen)
    _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_FontFamilyDispose($hFontFamily)
    _GDIPlus_Shutdown()
EndFunc

 

When the words fail... music speaks.

Link to comment
Share on other sites

@Andreik I don't know what text I'm going to find because it's a video window that plays a .cdg file and each song has a text.

@UEZ in this case it would not be in images but in a video playing cdg file.

I think that identifying the text of another window and putting an outline around it must not be possible at all.

Edited by Belini
Link to comment
Share on other sites

  • 7 months later...
Func _CreateLabel($_text, $_x, $_y, $_w = Default, $_h = Default, $_style = Default, $_fgcol = Default, $_bkcol = 0)
    Local $_d[4][2] = [[0, -1], [0, 1], [-1, 0], [1, 0]]
    For $_z = 0 To 3
        GUICtrlCreateLabel($_text, $_x + $_d[$_z][0], $_y + $_d[$_z][1], $_w, $_h, $_style)
        GUICtrlSetColor(-1, $_bkcol)
        GUICtrlSetBkColor(-1, -2)
    Next
    $_label = GUICtrlCreateLabel($_text, $_x, $_y, $_w, $_h, $_style)
    GUICtrlSetColor(-1, $_fgcol)
    GUICtrlSetBkColor(-1, -2)
    Return $_label
EndFunc

Func _SetLabelData($_handle, $_data)
    For $_z = 0 To 4
        GUICtrlSetData($_handle - $_z, $_data)
    Next
EndFunc

Simple solution as replacement for your GUICtrlCreateLabel() and GUICtrlSetData()

Link to comment
Share on other sites

I tested it here with some changes and found it interesting

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

global $_label, $Form1

$Form1 = GUICreate("Form1", 400, 150, -1, -1)
_CreateLabel("TESTE", 40, 50, 640, 50, Default, Default, 0X00FF00, "Arial", 30)
_SetLabelData($_label, "TESTANDO")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _CreateLabel($_text, $_x, $_y, $_w = Default, $_h = Default, $_style = Default, $_fgcol = Default, $_bkcol = 0, $ft_type = "Arial", $ft_size = 12)
    Local $_d[4][2] = [[0, -1], [0, 1], [-1, 0], [1, 0]]
    For $_z = 0 To 3
        GUICtrlCreateLabel($_text, $_x + $_d[$_z][0], $_y + $_d[$_z][1], $_w, $_h, $_style)
        GUICtrlSetFont(-1, $ft_size, 400, 4, $ft_type)
        GUICtrlSetColor(-1, $_bkcol)
        GUICtrlSetBkColor(-1, -2)
    Next
    $_label = GUICtrlCreateLabel($_text, $_x, $_y, $_w, $_h, $_style)
    GUICtrlSetFont(-1, $ft_size, 400, 4, $ft_type)
    GUICtrlSetColor(-1, $_fgcol)
    GUICtrlSetBkColor(-1, -2)
    Return $_label
EndFunc

Func _SetLabelData($_handle, $_data)
    For $_z = 0 To 4
        GUICtrlSetData($_handle - $_z, $_data)
    Next
EndFunc

 

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...