Что нового

картинка с текстом

saraconor

Новичок
Сообщения
420
Репутация
3
Подскажите, что я делаю не так, должна создаваться картинка с текстом, но текста почему-то нет.
Код:
#include <GDIPlus.au3>

; Инициализация GDI+
_GDIPlus_Startup()

; Размеры изображения
Local $iWidth = 500
Local $iHeight = 500

; Создание нового изображения
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)

; Установка белого фона
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
_GDIPlus_GraphicsFillRect($hGraphics, 0, 0, $iWidth, $iHeight, $hBrush)
_GDIPlus_BrushDispose($hBrush)

; Рисуем текст
Local $hFont = _GDIPlus_FontCreate("Arial", 48, 1) ; Размер шрифта 48
Local $hFormat = _GDIPlus_StringFormatCreate()
Local $hBrushText = _GDIPlus_BrushCreateSolid(0xFF000000) ; Черный цвет текста
Local $sText = "Привет мир"

; Вычисляем размер текста
Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iWidth, $iHeight)
Local $tSize = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat)

; Вычисляем позицию для центрирования текста
Local $x = ($iWidth - DllStructGetData($tSize, "Width")) / 2
Local $y = ($iHeight - DllStructGetData($tSize, "Height")) / 2

; Рисуем текст в центре
_GDIPlus_GraphicsDrawString($hGraphics, $sText, $hFont, $x, $y, $hFormat, $hBrushText)

; Освобождаем ресурсы
_GDIPlus_FontDispose($hFont)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrushText)

; Сохранение изображения
Local $sOutputPath = @DesktopDir & "\TextImage.jpg"
_GDIPlus_ImageSaveToFile($hBitmap, $sOutputPath)

; Освобождение ресурсов
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)

_GDIPlus_Shutdown()
 

InnI

AutoIT Гуру
Сообщения
4,959
Репутация
1,450
Код:
#include <GDIPlus.au3>

; Инициализация GDI+
_GDIPlus_Startup()

; Размеры изображения
Local $iWidth = 500
Local $iHeight = 500

; Создание нового изображения
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)

; Установка белого фона
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
_GDIPlus_GraphicsFillRect($hGraphics, 0, 0, $iWidth, $iHeight, $hBrush)
_GDIPlus_BrushDispose($hBrush)

; Рисуем текст
Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
Local $hFont = _GDIPlus_FontCreate($hFamily, 48, 1) ; Размер шрифта 48
Local $hFormat = _GDIPlus_StringFormatCreate()
Local $hBrushText = _GDIPlus_BrushCreateSolid(0xFF000000) ; Черный цвет текста
Local $sText = "Привет мир"

; Вычисляем размер текста
Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iWidth, $iHeight)
Local $aSize = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat)

; Вычисляем позицию для центрирования текста
$tLayout.X = ($iWidth - DllStructGetData($aSize[0], "Width")) / 2
$tLayout.Y = ($iHeight - DllStructGetData($aSize[0], "Height")) / 2

; Рисуем текст в центре
_GDIPlus_GraphicsDrawStringEx($hGraphics, $sText, $hFont, $tLayout, $hFormat, $hBrushText)

; Освобождаем ресурсы
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_FontDispose($hFont)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrushText)

; Сохранение изображения
Local $sOutputPath = @DesktopDir & "\TextImage.jpg"
_GDIPlus_ImageSaveToFile($hBitmap, $sOutputPath)

; Освобождение ресурсов
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)

_GDIPlus_Shutdown()
 
Верх