ImageMagick: Rotar Una Imagen


Subject: ImageMagick: Rotar Una Imagen
Nuestro Jedi-Gambas shordi, que me nombró Caballero Jedi, con nombre " Obi-Vuott-Kenobi ", pero pidió un codigo gambas con funciones externas del API de "ImageMagick" para rotar una imagen.

La Fuerza abraza los Jedi y todo el Universo !


Library "libMagickWand-6.Q16:2.0.0" ' Podeis usar tambien la libreria "libMagickWand:5.0.0" !!!

Public Struct PixelWand
id As Long
name[4096] As Byte
exception As Pointer
pixel As Integer
count As Long
debug_ As Boolean
signature As Long
End Struct

Private Enum MagickFalse = 0, MagickTrue

' void MagickWandGenesis(void)
' Initializes the MagickWand environment.
Private Extern MagickWandGenesis()

' MagickWand *NewMagickWand(void)
' Returns a wand required for all other methods in the API.
Private Extern NewMagickWand() As Pointer

' MagickBooleanType MagickReadImage(MagickWand *wand,const char *filename)
' Reads an image or image sequence.
Private Extern MagickReadImage(wand As Pointer, filename As String) As Boolean

' PixelWand *NewPixelWand(void)
' Returns a new pixel wand.
Private Extern NewPixelWand() As PixelWand

' void PixelSetRed(PixelWand *wand, const double red)
' Sets the normalized red color of the pixel wand.
Private Extern PixelSetRed(Pwand As PixelWand, red As Float)

' void PixelSetGreen(PixelWand *wand, const double green)
' Sets the normalized green color of the pixel wand.
Private Extern PixelSetGreen(Pwand As PixelWand, green As Float)

' void PixelSetBlue(PixelWand *wand, const double blue)
' Sets the normalized blue color of the pixel wand.
Private Extern PixelSetBlue(Pwand As PixelWand, blue As Float)

' void PixelSetAlpha(PixelWand *wand, const double alpha)
' Sets the normalized alpha color of the pixel wand.
Private Extern PixelSetAlpha(Pwand As PixelWand, alpha As Float)

' MagickBooleanType MagickRotateImage(MagickWand *wand, const PixelWand *background,const double degrees)
' Rotates an image the specified number of degrees.
Private Extern MagickRotateImage(wand As Pointer, background As PixelWand, degrees As Float) As Boolean

' MagickBooleanType MagickWriteImages(MagickWand *wand, const char *filename,const MagickBooleanType adjoin)
' Writes an image or image sequence.
Private Extern MagickWriteImages(wand As Pointer, filename As String, adjoin As Boolean) As Boolean

' PixelWand *DestroyPixelWand(PixelWand *wand)
' Deallocates resources associated with a PixelWand.
Private Extern DestroyPixelWand(Pwand As PixelWand) As PixelWand

' MagickWand *DestroyMagickWand(MagickWand *wand)
' Deallocates memory associated with an MagickWand.
Private Extern DestroyMagickWand(wand As Pointer) As Pointer

' void MagickWandTerminus(void)
' Terminates the MagickWand environment.
Private Extern MagickWandTerminus()


Public Sub Main()

Dim bo As Boolean
Dim magickwand As Pointer
Dim fileimagen, nuevofile As String
Dim pw As PixelWand

fileimagen = "/ruta/del/archivo/imagen"
nuevofile = "/ruta/del/nuevo/archivo/de/la/imagen/rotada"

MagickWandGenesis()

' Los triángulos dejados vacíos de la rotación de la imagen son llenados de un color de fondo:
pw = ColorFondo()

magickwand = NewMagickWand()

bo = MagickReadImage(magickwand, fileimagen)
If bo = MagickFalse Then
Termina(magickwand, pw)
Error.Raise("Impossible cargar imagen !")
Endif

' Rota la imagen de 135,00° a la derecha:
MagickRotateImage(magickwand, pw, 135.00)

bo = MagickWriteImages(magickwand, nuevofile, MagickTrue)
If bo = MagickFalse Then
Termina(magickwand, pw)
Error.Raise("Impossible crear el nuovo archivo imagen !")
Endif

' Libera la memoria y acaba la libreria "ImageMagick":
Termina(magickwand, pw)

End


Private Function ColorFondo() As PixelWand

Dim pxw As PixelWand

pxw = NewPixelWand()
PixelSetRed(pxw, 255.0)
PixelSetGreen(pxw, 255.0)
PixelSetBlue(pxw, 255.0)
' Impone el canal Alfa a cero por la transparencia:
PixelSetAlpha(pxw, 0.0)

Return pxw

End


Private Procedure Termina(mw As Pointer, pixw As PixelWand) ' Memoriam liberat et programma terminat !

DestroyPixelWand(pixw)
DestroyMagickWand(mw)
Wait 0.01
MagickWandTerminus()

End

Last edited by vuott on Wednesday, 07 June 2017, 16:28; edited 3 times in total
Profile PM  
Subject: Re: ImageMagick: Rotar Una Imagen
Genial. Muchas Gracias. Justo lo que necesitaba.

¡Aúpa Jedis! Viva el lado luminoso y blanco.

¡Los Sith son del Barça!

Profile PM  

Page 1 of 1


  
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events

   

This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.

Powered by Icy Phoenix based on phpBB
Design by DiDiDaDo

Generation Time: 0.1329s (PHP: -1% SQL: 101%)
SQL queries: 24 - Debug Off - GZIP Enabled