atvaxn Posted March 1 Share Posted March 1 Hi, I want to add text to an image. When showing the bitmap with GUI its ok. As soon as I export it to JPG, there is no anti-aliasing, so the text looks ugly. Do you have some solutions? #include <GDIPlus.au3> _GDIPlus_Startup() Local Const $iW = 460, $iH = 100 Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;create an empty bitmap Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the graphics context of the bitmap _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hBmpCtxt, 0xFFFFFFFF) ;clear bitmap with color white _GDIPlus_GraphicsDrawString($hBmpCtxt, "AutoIt rulez!", 0, 0, "ARIAL", 52) ;draw some text to the bitmap Local $sFile = "D:\Test.jpg" _GDIPlus_ImageSaveToFile($hBitmap, $sFile) ;save bitmap to disk ;cleanup GDI+ resources _GDIPlus_GraphicsDispose($hBmpCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() ShellExecute($sFile) ;open bitmap with default app Link to comment Share on other sites More sharing options...
ioa747 Posted March 1 Share Posted March 1 (edited) #include <GDIPlus.au3> _GDIPlus_Startup() Local Const $iW = 460, $iH = 100 Local $iScale = 10 Local $iBMP_W = Ceiling($iW * $iScale) Local $iBMP_H = Ceiling($iH * $iScale) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iBMP_W, $iBMP_H) Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the graphics context of the bitmap _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hBmpCtxt, 0xFFFFFFFF) ;clear bitmap with color white _GDIPlus_GraphicsDrawString($hBmpCtxt, "AutoIt rulez!", 0, 0, "ARIAL", Ceiling(52 * $iScale)) Local $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, $iBMP_W / $iScale, $iBMP_H / $iScale) ;resize image Local $sFile = @ScriptDir & "\Test1.jpg" Local $sFile2 = @ScriptDir & "\Test2.jpg" _GDIPlus_ImageSaveToFile($hBitmap_Scaled, $sFile) _GDIPlus_ImageSaveToFile($hBitmap, $sFile2) ;cleanup GDI+ resources _GDIPlus_GraphicsDispose($hBmpCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BitmapDispose($hBitmap_Scaled) _GDIPlus_Shutdown() ShellExecute($sFile) ;open bitmap with default app Sleep(1000) ShellExecute($sFile2) ;open bitmap with default app Edited March 1 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
UEZ Posted March 1 Share Posted March 1 Use _GDIPlus_GraphicsSetTextRenderingHint to smooth string drawings. ioa747 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ 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