marcoauto Posted May 29, 2018 Share Posted May 29, 2018 Ciao, I tried to write a text on a transparent png file, but I write text but without background. This is my script: expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Andreik Posted May 29, 2018 Share Posted May 29, 2018 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. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
marcoauto Posted May 29, 2018 Author Share Posted May 29, 2018 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now