Jump to content

GDI+ text stroke effects


marcoauto
 Share

Recommended Posts

Ciao,

Is there a function to create a stroke text?

I have found the solution to fill the text with a texture, to make a shadow and to make a text with glow , but I can't reproduce the stoke effect.)

I have attached an example image of what I would like to reproduce

I have tried to adapt this script of Malkey but with no result

The Malkey script is this (I have edit some line) and the original post is here: 

 

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
Global $nPI = 3.1415926535897932384626433832795

Global $ghGDIPDll

$hWnd = GUICreate("GDI+ Example", 800, 150)

$iGlow = 2; <== Amount of Glow min = 1 Max about 5

_GDIPlus_Startup()
$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics(800, 150, $hGraphicGUI)
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
_GDIPlus_GraphicsClear($hGraphics, 0xff003000)  ; Black-green background
;~ _GDIPlus_GraphicsClear($hGraphics, 0xffffffff) ; White Background
_AntiAlias($hGraphics, 4)

$hFamily = _GDIPlus_FontFamilyCreate("Arial Black")
$hFont = _GDIPlus_FontCreate($hFamily, 80)
$hLayout = _GDIPlus_RectFCreate(0, 0, 800, 150)
$hStringFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hStringFormat, 1)

For $i = 1 To 15 Step 3
    $hBrush3 = _GDIPlus_BrushCreateSolid("0x" & hex($iGlow,2) & "00ff00"); <====== Glow (Transparency)
    For $x = 0 To 360 Step 3
        DllStructSetData($hLayout, "Y", ((18 - $i)) * Sin($x * $nPI / 180))
        DllStructSetData($hLayout, "X", ((18 - $i)) * Cos($x * $nPI / 180))
        $hStringFormat = _GDIPlus_StringFormatCreate()
        _GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush3)
    Next
Next
DllStructSetData($hLayout, "Y", 0)
DllStructSetData($hLayout, "X", 0)
$hStringFormat = _GDIPlus_StringFormatCreate()
$hBrush3 = _GDIPlus_BrushCreateSolid("0xfF00FF00")
_GDIPlus_GraphicsDrawStringEx($hGraphics, "AutoIt Rocks", $hFont, $hLayout, $hStringFormat, $hBrush3)
GUISetState()

GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)
GUIRegisterMsg(0x85, "MY_PAINT") ; $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize.
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

_GDIPlus_BrushDispose($hBrush3)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_StringFormatDispose($hStringFormat)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hGraphicGUI)
_WinAPI_DeleteObject($hBMPBuff)
_GDIPlus_Shutdown()

Func _AntiAlias($hGraphics, $iMode)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $iMode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_AntiAlias

;Func to redraw on PAINT MSG
Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
    _WinAPI_RedrawWindow($hWnd, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)) ; , $RDW_ALLCHILDREN
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_PAINT

Thank you very much,

Marco

autoit.png

Link to comment
Share on other sites

Try something like this here:

;coded by UEZ build 2016-12-31
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

_GDIPlus_Startup()
Global $hBitmap_StrokeText = _GDIPlus_BitmapeCreateStrokeText("AutoIt", "Arial Black", 300, 0xF0035D8B, 0xFF41ABE1, 0xFFFFFFFF)
Global $aDim = _GDIPlus_ImageGetDimension($hBitmap_StrokeText)
Global $hGUI = GUICreate("GDI+ Stroke Text Example", $aDim[0], $aDim[1])
GUISetBkColor(0xFAFAFA)
GUISetState()
Global $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImageRect($hGfx, $hBitmap_StrokeText, 0, 0, $aDim[0], $aDim[1])

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose($hGfx)
            _GDIPlus_BitmapDispose($hBitmap_StrokeText)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

Func _GDIPlus_BitmapeCreateStrokeText($sText, $sFont = "Arial Black", $fSize = 300.0, $iC1 = 0xFFFF0000, $iC2 = 0xFF00FF00, $iC3 = 0xFF0000FF, $fBlur = 20.0)
    Local Const $hPath = _GDIPlus_PathCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local $tLayout = _GDIPlus_RectFCreate()
    _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fSize, $hFormat)
    Local Const $aBounds = _GDIPlus_PathGetWorldBounds($hPath)
    Local $iW = $aBounds[2] * 3, $iH = $aBounds[3] * 3
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
    _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 4)
    _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, 2)
;~  Local Const $hBrush = _GDIPlus_BrushCreateSolid($iC3)
    Local Const $hBrush = _GDIPlus_LineBrushCreate(0, 0, $aBounds[2] / 9, $aBounds[3] / 2, $iC3, 0xC8D8D8FF, 0)
    _GDIPlus_LineBrushSetSigmaBlend($hBrush, 0.1, 0.5)
    _GDIPlus_LineBrushSetGammaCorrection($hBrush, 1)
    Local Const $hPen = _GDIPlus_PenCreate()
    _GDIPlus_PenSetLineJoin($hPen, 2)
    _GDIPlus_PenSetColor($hPen, $iC1)
    Local Const $fBorder = $fSize / 5.5
    _GDIPlus_PenSetWidth($hPen, $fBorder)
    _GDIPlus_PenSetAlignment($hPen, 0)
    _GDIPlus_GraphicsDrawPath($hCanvas, $hPath, $hPen)
    Local Const $hEffect = _GDIPlus_EffectCreateBlur($fBlur)
    _GDIPlus_BitmapApplyEffect($hBitmap, $hEffect)
    _GDIPlus_PenSetColor($hPen, $iC2)
    _GDIPlus_PenSetWidth($hPen, $fSize / 10)
    _GDIPlus_PenSetAlignment($hPen, 0)
    _GDIPlus_GraphicsDrawPath($hCanvas, $hPath, $hPen)
    _GDIPlus_GraphicsFillPath($hCanvas, $hPath, $hBrush)
    Local Const $aPoints = _GDIPlus_PathGetLastPoint($hPath)
    Local Const $aBitmap_Cropped = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $aPoints[0] + 2 * $aBounds[0] + $fBorder, $aPoints[1] + 2 * $aBounds[1] + $fBorder, $GDIP_PXF32ARGB)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_EffectDispose($hEffect)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hCanvas)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    Return $aBitmap_Cropped
EndFunc   ;==>_GDIPlus_BitmapeCreateStrokeText

 

If you change the font then _GDIPlus_BitmapCloneArea (line 57) needs to be adjusted appropriately.

Edited by UEZ
small modifications

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

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

×
×
  • Create New...