Jump to content

Text to PNG - Bold ugly text on transparent background - GDIplus


Blaxxun
 Share

Recommended Posts

#include <GDIPlus.au3>

Text2PNG(@DesktopDir & "\MyPNG.png", 0x00FFFFFF) ; Transparent but bold ugly text
;Text2PNG(@DesktopDir & "\MyPNG.png", 0xFFFFFFFF) ; Nice Text but not transparent

Func Text2PNG($sFile, $iColor)
    _GDIPlus_Startup()
    Local $hImage = _GDIPlus_BitmapCreateFromScan0(50, 25)
    Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage)
    _GDIPlus_GraphicsClear($hGraphics, $iColor)
    _GDIPlus_GraphicsDrawString($hGraphics, "Hello", 0, 0, "Arial", 12, 0)
    _GDIPlus_ImageSaveToFile($hImage, $sFile)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_Shutdown()
EndFunc   ;==>Text2PNG

 

Hello ladys and gentlemen,

I have this piece of code and it does what it's supposed to do.

I want to use it to create an image sequence with frame/image information for compositing overlay.

However, when i use a transparent background the text starts to look kinda bold or fat.

I dont know what causes this ugly effect.

Is there a way to avoid this effect somehow?

Thanks!

 

 

Link to comment
Share on other sites

You have to activate anti aliasing.

#include <GDIPlus.au3>

Text2PNG(@DesktopDir & "\MyPNG.png", 0x00FFFFFF) ; Transparent but bold ugly text
;Text2PNG(@DesktopDir & "\MyPNG.png", 0xFFFFFFFF) ; Nice Text but not transparent

Func Text2PNG($sFile, $iColor)
    _GDIPlus_Startup()
    Local $hImage = _GDIPlus_BitmapCreateFromScan0(50, 25)
    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", 12, 0)
    _GDIPlus_ImageSaveToFile($hImage, $sFile)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_Shutdown()
EndFunc   ;==>Text2PNG

 

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

Thank you very much UEZ ! :)

The text looks good now on transparent background.

I just wonder why one has to use AA on transparent bg when the same text looks fine on opaque bg without AA. ^^

Interesting. I would'nt have thought about using AA myself.

 

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