memerim Posted July 21, 2021 Posted July 21, 2021 (edited) #include <GDIPlus.au3> Text2PNG(@ScriptDir & "\x_2.png", 0x7DFFFFFF) ; Transparent text Func Text2PNG($sFile, $iColor) _GDIPlus_Startup() Local $hImage = _GDIPlus_BitmapCreateFromFile ( $sFile ) ;Local $hImage = _GDIPlus_BitmapCreateFromScan0(400, 250) ;$sFile2 = @ScriptDir & "\x_3.png" ;_GDIPlus_ImageSaveToFile($hImage, $sFile2) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $GDIP_TEXTRENDERINGHINT_ANTIALIAS) _GDIPlus_GraphicsClear($hGraphics, $iColor) _GDIPlus_GraphicsDrawString($hGraphics, "Hello", 0, 0, "Arial", 32, 0) _GDIPlus_ImageSaveToFile($hImage, $sFile) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hImage) _GDIPlus_Shutdown() EndFunc ;==>Text2PNG The image is at 50% transparency, im trying to write the text on it with the same transparency. What transparency lvl the text will need to be drawn, to achieve the same transparency as on the image, 50% too? (0x7DFFFFFF) But atm it does not draw anything unless i create a new bitmap from scan, whats going on? Spoiler Edited July 21, 2021 by memerim
UEZ Posted July 22, 2021 Posted July 22, 2021 (edited) Try this: #include <GDIPlus.au3> Text2PNG(@ScriptDir & "\x_2.png", 0xE0FFFFFF) ; Transparent text ShellExecute(@ScriptDir & "\x_2.png") Func Text2PNG($sFile, $iColor) _GDIPlus_Startup() Local $hImage = _GDIPlus_BitmapCreateFromScan0(400, 250) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsClear($hGraphics, 0x7F000000) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $GDIP_TEXTRENDERINGHINT_ANTIALIAS) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Consolas") Local $hFont = _GDIPlus_FontCreate($hFamily, 32) Local $hBrush = _GDIPlus_BrushCreateSolid($iColor) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) _GDIPlus_GraphicsDrawStringEx($hGraphics, "Hello World", $hFont, _GDIPlus_RectFCreate(0, 0, 400, 250), $hFormat, $hBrush) _GDIPlus_ImageSaveToFile($hImage, $sFile) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hImage) _GDIPlus_Shutdown() EndFunc ;==>Text2PNG Edited July 23, 2021 by UEZ 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
memerim Posted July 22, 2021 Author Posted July 22, 2021 Hello @UEZ, the script resulted in a image without background, just the text, i would like to keep the background and just draw the text over it with the same level of transparency. The result im trying to achieve is something similar to this image: Spoiler Its the same image of my first post, but now with the text drawn, and both have the same level of transparency.
UEZ Posted July 22, 2021 Posted July 22, 2021 Just add _GDIPlus_GraphicsClear($hGraphics, 0xFF7F7F7F) after Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) and it should work as expected. 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
memerim Posted July 22, 2021 Author Posted July 22, 2021 #include <GDIPlus.au3> Text2PNG(@ScriptDir & "\x_2.png", 0x7DFFFFFF) ; Transparent text ShellExecute(@ScriptDir & "\x_2.png") Func Text2PNG($sFile, $iColor) _GDIPlus_Startup() Local $hImage = _GDIPlus_BitmapCreateFromScan0(400, 250) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsClear($hGraphics, 0xFF7F7F7F) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $GDIP_TEXTRENDERINGHINT_ANTIALIAS) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Arial") Local $hFont = _GDIPlus_FontCreate($hFamily, 32) Local $hBrush = _GDIPlus_BrushCreateSolid($iColor) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) _GDIPlus_GraphicsDrawStringEx($hGraphics, "Hello World", $hFont, _GDIPlus_RectFCreate(0, 0, 400, 250), $hFormat, $hBrush) _GDIPlus_ImageSaveToFile($hImage, $sFile) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hImage) _GDIPlus_Shutdown() EndFunc ;==>Text2PNG Now the image have no transparency: Spoiler
UEZ Posted July 22, 2021 Posted July 22, 2021 (edited) If you mean the background then set alpha channel of _GDIPlus_GraphicsClear($hGraphics, 0x7F7F7F7F) (ARGB) accordingly. Here 0x7F is semi-transparent. Edited July 23, 2021 by UEZ junkew 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
memerim Posted July 23, 2021 Author Posted July 23, 2021 (edited) Thank you UEZ, the image generated by the script have much more less quality when you compare with this one: Edited July 23, 2021 by memerim
UEZ Posted July 23, 2021 Posted July 23, 2021 (edited) The code above produces this output: You have to adjust the color of the background / text accordingly. Edited July 23, 2021 by UEZ 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
memerim Posted July 23, 2021 Author Posted July 23, 2021 (edited) And when the image is not just a single color but a gradient like this: Edited July 23, 2021 by memerim
UEZ Posted July 23, 2021 Posted July 23, 2021 Then look into the help file to checkout how to create a gradient background. 😉 memerim 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
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