Что нового

Как написать текст на изображении

---Zak---

Скриптер
Сообщения
455
Репутация
120
Добрый всем день.

Уже 3 часа ломаю себе голову, но ничего интересного не придумал.
Имеется скрипт, который выводит png и с возможностью перемещения (взято от сюда - http://autoit-script.ru/index.php/topic,9289.0.html)

Код:
#Include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>
#include <Misc.au3>
#Include <GDIPlus.au3>
#Include <WinAPIEx.au3>

Global $hForm

Func1()
Do
Until GUIGetMsg() = -3

Func Func1()
_GDIPlus_Startup()
$hPng = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\0.jpg")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPng)
$hForm = GUICreate('', _GDIPlus_ImageGetWidth($hPng), _GDIPlus_ImageGetHeight($hPng), 200, 200,$WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
_WinAPI_UpdateLayeredWindowEx($hForm, 200, 200, $hBitmap, 255, 1)
;~ /////////////////////////
;~    $hGraphic = ????????????????????
;~    _GDIPlus_GraphicsDrawString($hGraphic, "Hello world", 140, 110)
;~ /////////////////////////
_GDIPlus_ImageDispose($hPng)
_GDIPlus_Shutdown()
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')
GUISetState()
WinSetOnTop ( $hForm, "", 1 )
EndFunc


Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $hWnd
        Case $hForm
            Return $HTCAPTION
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST

Но как на этом всем (картинке) написать текст ?
Код:
_GDIPlus_GraphicsDrawString($hGraphic, "Hello world", 140, 110)
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Вот пример:
Код:
#Include <GDIPlus.au3>

$sText = 'Text'

$iLeft = 200
$iTop = 200

$xColor = 0xFFFFD823
$iFontSize = 24
$iFontStyle = 0

_GDIPlus_Startup()
$hFamily = _GDIPlus_FontFamilyCreate('Arial')
$hFont   = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontStyle)
$hFormat = _GDIPlus_StringFormatCreate()


$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\base.jpg')
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
$tLayout  = _GDIPlus_RectFCreate($iLeft, $iTop)
$hBrush  = _GDIPlus_BrushCreateSolid($xColor)
$aInfo    = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)

_GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $aInfo[0], $hFormat, $hBrush)
_GDIPlus_ImageSaveToFileEx($hImage, @ScriptDir & '\new.jpg', _GDIPlus_EncodersGetCLSID ('JPG'))
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage  )

_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_Shutdown()
 
Автор
---Zak---

---Zak---

Скриптер
Сообщения
455
Репутация
120
Все понял - получилось... оказывается не туда просто писал
Код:
#Include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>
#include <Misc.au3>
#Include <GDIPlus.au3>
#Include <WinAPIEx.au3>

Global $hForm

Func1()
Do
Until GUIGetMsg() = -3

Func Func1()
_GDIPlus_Startup()
$hPng = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\0.jpg")

$hGraphic = _GDIPlus_ImageGetGraphicsContext($hPng)
_GDIPlus_GraphicsDrawString($hGraphic, "Hello world", 10, 10)

$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hPng)

$hForm = GUICreate('', _GDIPlus_ImageGetWidth($hPng), _GDIPlus_ImageGetHeight($hPng), 200, 200,$WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))

_WinAPI_UpdateLayeredWindowEx($hForm, 200, 200, $hBitmap, 255, 1)
_GDIPlus_ImageDispose($hPng)
_GDIPlus_Shutdown()
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')
GUISetState()
WinSetOnTop ( $hForm, "", 1 )
EndFunc


Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $hWnd
        Case $hForm
            Return $HTCAPTION
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST
 
Верх