Sign in to follow this  
Followers 0
DatMCEyeBall

GDI+ - Draw text to a png file and save it

3 posts in this topic

Before I say type anything this is proberbly a question that has been asked already. I searched the forum and couldn't find anything.

The question is:

How do I draw a string (in this case every letter from chr(33) to chr(126)) with GDI+ and save them to a seperate .png file?

I have some code bet it doesn't work correctly. (I want alpha transpareny on each background)

#include <GDIPlus.au3>

_GDIPlus_Startup()
$h_bitmap = _WinAPI_CreateBitmap(20, 20, 1, 32)
$h_image = _GDIPlus_BitmapCreateFromHBITMAP($h_bitmap)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($h_image)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)

$sString = "S"
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 18, 0, 2)
$tLayout = _GDIPlus_RectFCreate(0, 0, 20, 20)
$aInfo = _GDIPlus_GraphicsMeasureString($h_image, $sString, $hFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($h_image, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)

_GDIPlus_ImageSaveToFile($h_image, "S.png")

_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)

_GDIPlus_ImageDispose($h_image)
_WinAPI_DeleteObject($h_bitmap)
_GDIPlus_Shutdown()

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Share this post


Link to post
Share on other sites



Try this: Write Text on Bitmap (German site).

 

Br,

UEZ

Thanks I'll try that and post the results.


"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Share this post


Link to post
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
Sign in to follow this  
Followers 0