Página 1 de 1

Escribir texto en una imagen

Publicado: 02 Abr 2014, 23:34
por marcrusi
Buenas noches!!!

Queria saber si puedo abrir una imagen que tengo guardada en el ordenador (.png) y escribir en un lateral de la imagen una serie de variables... He intentado hacer algo de GDI+ pero no me ha servido... Aquí os dejo lo que he intentado...

Código: Seleccionar todo

$espera = 6*60000
$anyo = @YEAR
$mes = @MON
$dia = @MDAY
$hora = 0
$minute = "00"
$sFileName = "C:\Users\marc\Desktop\CurrentCDV\CDV_Current_PPI.png"
$hImage = _GDIPlus_ImageLoadFromFile($sFileName)
$hGraphics = _GDIPlus_ImageGetGraphicsContext ($hImage)
$sString = $anyo & "-" & StringFormat("%02d",$mes) & "-" &  StringFormat("%02d",$dia) & "    " & StringFormat("%02d",$hora) & ":" & $minutes
$nX = 5
$nY = 5
_GDIPlus_GraphicsDrawString($hGraphics, $sString, $nX, $nY[, $sFont = "Arial"[, $fSize = 10[, $iFormat = 0]]])
   
sleep ($espera)
¨

Una vez genero el .exe y lo ejecuto me aparece el mensaje de error

Line 3054 (File "C/......exe")
Error: Variable used without being declared

Haber si alguien me dice si lo que pretendo se puede hacer y si se puede, que es lo que hago mal...

Re: Escribir texto en una imagen

Publicado: 03 Abr 2014, 19:26
por Dany
Hola bienvenido al foro.

algo como esto:

Código: Seleccionar todo

#include <GDIPlus.au3>


_AddTextToPic ( 'entrada.png', 'Salida.png', "Lo que quieres escribir", 0, 0 )
Exit

Func _AddTextToPic ( $_ImagePath, $_Outputpath, $sString, $_X=0, $_Y=0 )
    Local $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen
    ; Initialize GDI+ library
    _GDIPlus_StartUp ( )
    ; Load image and emboss text
    $hImage   = _GDIPlus_ImageLoadFromFile ( $_ImagePath )
    $hGraphic = _GDIPlus_ImageGetGraphicsContext ( $hImage )
    $hFamily  = _GDIPlus_FontFamilyCreate ( "Arial" )
    $hFont    = _GDIPlus_FontCreate ( $hFamily, 20, 1 )
    $hFormat  = _GDIPlus_StringFormatCreate ( 0x4000 )
    $hBrush2  = _GDIPlus_BrushCreateSolid ( 0xff000000 )
    $hPen     = _GDIPlus_PenCreate ( 0xC4000000, 1 )
    ; Set Text Pos
    $tLayout  = _GDIPlus_RectFCreate ( $_X, $_Y )
    $aInfo    = _GDIPlus_GraphicsMeasureString ( $hGraphic, $sString, $hFont, $tLayout, $hFormat )
    _GDIPlus_GraphicsDrawStringEx ( $hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush2 )
    ; Save image
    _GDIPlus_ImageSaveToFile ( $hImage, $_Outputpath )
    ; Free resources
    _GDIPlus_PenDispose ( $hPen )
    _GDIPlus_BrushDispose ( $hBrush1 )
    _GDIPlus_BrushDispose ( $hBrush2 )
    _GDIPlus_StringFormatDispose ( $hFormat )
    _GDIPlus_FontDispose ( $hFont )
    _GDIPlus_FontFamilyDispose ( $hFamily )
    _GDIPlus_GraphicsDispose ( $hGraphic )
    _GDIPlus_ImageDispose ( $hImage )
    _GDIPlus_ShutDown ( )
EndFunc ;==> _AddTextToPic ( )
saludos

Re: Escribir texto en una imagen

Publicado: 04 Abr 2014, 13:29
por marcrusi
Exactamente era esto lo que queria!!

Muchas gracias :P

Re: Escribir texto en una imagen

Publicado: 04 Abr 2014, 13:58
por marcrusi
Ya que estamos.... Habria alguna manera de superponer imagenes?

Es decir, tengo 3 imagenes y las quiero superponer todas una encima de la otra... Haber si alguien me ayuda :smt003