Jump to content

Add Text to Bitmap with smoothingd


Recommended Posts

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

_SCREENSHOT_240301_114150.jpg

_SCREENSHOT_240301_114218.jpg

Link to comment
Share on other sites

#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 by ioa747

I know that I know nothing

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...