Jump to content

Recommended Posts

Posted

Ciao,

I tried to write a text on a transparent png file, but I write text but without background.

This is my script:

 

#include <GDIPlus.au3>


_GDIPlus_Startup()

Global $circle_base = "circle.png"

for $sString = 1 to 90
    $hBrushNumber = _GDIPlus_BrushCreateSolid(0xFF014990)
    $hImagetemp = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\" & $circle_base)
    $iPenWidth = 0
    $hPenNumber = _GDIPlus_PenCreate(0xFF014990, $iPenWidth)
    $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate()
    $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, 0) ;0 = opaque, -1 = transparent
    _GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, DllStructGetPtr($tColorMatrix))

    $g_aDim = _GDIPlus_ImageGetDimension($hImagetemp)

    $g_hImage2 = _GDIPlus_BitmapCreateFromScan0($g_aDim[0], $g_aDim[1])
    $g_hGfx = _GDIPlus_ImageGetGraphicsContext($g_hImage2)

    $hFamily = _GDIPlus_FontFamilyCreate("Uni Sans Heavy CAPS") ;Create font family object
    $hPath = _GDIPlus_PathCreate() ;Create new path object
    $tLayout = _GDIPlus_RectFCreate(0,0) ;Create string bounding rectangle X=0, Y=0
    _GDIPlus_GraphicsSetSmoothingMode($g_hGfx, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;Sets the graphics object rendering quality (antialiasing)

    _GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 0, 63, 0) ;Add the outline of the string to the path

    $aBounds = _GDIPlus_PathGetWorldBounds($hPath) ;Get bounding rectangle of the path X-Y-Width-Height

    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix,(($g_aDim[0] - $aBounds[2])/2)-$aBounds[0], (($g_aDim[1] - $aBounds[3])/2)-$aBounds[1])   ;translate the matrix
    _GDIPlus_PathTransform($hPath, $hMatrix)    ;apply the above transofrmation
    _GDIPlus_GraphicsDrawPath($g_hGfx, $hPath, $hPenNumber) ;Draw path to graphics handle
    _GDIPlus_GraphicsFillPath($g_hGfx, $hPath, $hBrushNumber) ;Fill path with solid color

    _GDIPlus_ImageSaveToFile($g_hImage2, @ScriptDir & "\numbers\"&$sString&".PNG")
Next

_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_BrushDispose($hBrushNumber)
_GDIPlus_GraphicsDispose($g_hImage2)
_GDIPlus_Shutdown()

Thankyou

Marco

Posted

You didn't upload circle.png so we can see where your problem is and also what I could see at a quick preview of the code is a huge memory leak since you dispose just few objects of many created by your code.

Posted

ciao,

the source image circle.png is attached in this post. My result is 1.png, 2.png, etc (see 10.png attached like example). I'd like to write numbers on the circle. I upload a combined I did with a graphics program (result.png)

I know I need to dispose other objects, but this was a extract of all the code I wrote

Thanks

 

circle.png

10.PNG

result.png

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
  • Recently Browsing   0 members

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