Escribir Un Texto En Una Imagen Con Las Funciones Del API De Imlib2


Objetivo: Escribir Un Texto En Una Imagen Con Las Funciones Del API De Imlib2
Hola mis hemanos,
también podéis escribir un texto en una imagen sin activar un componente gráfico provisto por gambas. Es posible por ejemplo usando unas funciones de la librería externa de Imlib2:
Library "libImlib2:1.4.6"

' Imlib_Image imlib_load_image_immediately(const char *file)
' Loads an image from disk located at the path specified by file.
Private Extern imlib_load_image_immediately(filename As String) As Pointer

' void imlib_context_set_image(Imlib_Image image)
' Sets the current image Imlib2 will be using with its function calls.
Private Extern imlib_context_set_image(Imlib_Image As Pointer)

' Imlib_Font imlib_load_font(const char * font_name)
' Loads a truetype font from the first directory in the font path that contains that font.
Private Extern imlib_load_font(font_name As String) As Pointer

' void imlib_context_set_font(Imlib_Font font)
' Sets the current font to use when rendering text.
Private Extern imlib_context_set_font(font As Pointer)

' void imlib_text_draw(int x, int y, const char * text)
' Draws the null-byte terminated string text using the current font on the current image
' at the (x, y) location (x, y denoting the top left corner of the font string)
Private Extern imlib_text_draw(x As Integer, y As Integer, text As String)

' void imlib_context_set_color(int red, int green, int blue, int alpha)
' Sets the color with which text, lines and rectangles are drawn when being rendered onto an image.
Private Extern imlib_context_set_color(red As Integer, green As Integer, blue As Integer, alpha As Integer)

' void imlib_image_set_format(const char * format)
' Sets the format of the current image. This is used for when you wish to save an image in a different format
' that it was loaded in, or if the image currently has no file format associated with it.
Private Extern imlib_image_set_format(formato_immagine As String)

' void imlib_save_image(const char *filename)
' Saves the current image in the format specified by the current image's format settings to the filename filename.
Private Extern imlib_save_image(filename As String)


Public Sub Main()

Dim ImlibImage, fnt As Pointer

ImlibImage = imlib_load_image_immediately("/ruta/del/fichero/imagen")

imlib_context_set_image(ImlibImage)

' Especifica la ruta del font TTF que queremos utilizar (por ejemplo: Ubuntu-B.ttf), y la dimensión del caracter:
fnt = imlib_load_font("/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf/12")
If IsNull(fnt) Then Error.Raise("Error al cargar del font !")

' Elegimos un color para el texto (el ultimo a la derecha es el canal Alfa):
imlib_context_set_color(255, 255, 0, 255)

imlib_context_set_font(fnt)

' Escribe el texto especificando las sus coordinadas en la imagen:
imlib_text_draw(10, 20, "El nuestro texto")

' Especifica el tipo de fichero de imagen (por ejemplo "png"):
imlib_image_set_format("png")

imlib_save_image("/ruta/del/nuevo/fichero/imagen.png")

End

última edición por vuott el Domingo, 07 Diciembre 2014, 18:21; editado 5 veces
Perfil MP  
Objetivo: Re: Escribir Un Texto En Una Imagen Con Las Funciones Del API De Imlib2
¿Y no sería mejor ampliar el componente gb.image.imlib?
Ya sabéis que yo de C ni papa, pero si ya hay un componente que usa esa librería ¿por qué no ampliarlo?

Extraído de la ayuda del componente:
Citar:

Image (gb.image.imlib)
This class adds image processing methods coming from the imlib2 library.
Esta clase es Instanciable.
Métodos
Blur PaintImage Rotate Scroll Sharpen Stretch Tile


Añadir un método "Text" o "Title" o algo así no puede ser tan costoso... digo.

Saludos

Perfil MP  
Objetivo: Re: Escribir Un Texto En Una Imagen Con Las Funciones Del API De Imlib2
shordi escribió: [Ver mensaje]

Añadir un método "Text" o "Title" o algo así no puede ser tan costoso... digo.

...ya es posible escribir en una imagen con las Clases Draw y Paint.

Perfil MP  
Objetivo: Re: Escribir Un Texto En Una Imagen Con Las Funciones Del API De Imlib2
vuott:

Citar:
Es posible por ejemplo usando unas funciones de la librería externa de Imlib2:

¿de donde sacas esa información? ¿del comando man?

Saludos

Objetivo: Re: Escribir Un Texto En Una Imagen Con Las Funciones Del API De Imlib2
jsbsan escribió: [Ver mensaje]
Citar:
Es posible por ejemplo usando unas funciones de la librería externa de Imlib2:

¿de donde sacas esa información? ¿del comando man?


...no, estudiando el API de la librería
http://adesklets.sourcearchive.com/documentation/0.4.7/main.html
http://adesklets.sourcearchive.com/...0b366491a6.html
http://docs.enlightenment.org/api/imlib2/html/

y, cuando es posible, estudiando un ejemplo escrito en C.


saludos.

última edición por vuott el Lunes, 08 Diciembre 2014, 01:44; editado 1 vez
Perfil MP  
Objetivo: Re: Escribir Un Texto En Una Imagen Con Las Funciones Del API De Imlib2
Citar:
y, cuando es posible, estudiando un ejemplo escrito en C.


En españa se dice estar verde de envidia...

Perfil MP  
Objetivo: Re: Escribir Un Texto En Una Imagen Con Las Funciones Del API De Imlib2
shordi escribió: [Ver mensaje]
En españa se dice estar verde de envidia...


Ah !
En Italia esta frase se usa por la rabia, la cólera.

Saludosss

Perfil MP  

Página 1 de 1


  
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas
No puede adjuntar archivos
Puede descargar archivos
No puede publicar eventos en el calendario

   

Está utilizando la versión (Lo-Fi). Para ver la versión completa del foro, haga clic aquí.

Powered by Icy Phoenix based on phpBB
Design by DiDiDaDo

Página generada en:: 0.4666s (PHP: -74% SQL: 174%)
Consultas SQL: 47 - Debug off - GZIP Activado