Portal    Foro    Buscar    FAQ    Registrarse    Conectarse


Publicar nuevo tema  Responder al tema 
Página 1 de 1
 
 
ImageMagick: Rotar Una Imagen
Autor Mensaje
Responder citando   Descargar mensaje  
Mensaje 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

 



 
última edición por vuott el Miercoles, 07 Junio 2017, 16:28; editado 3 veces 
vuott - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje 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!      
 




===================
No podemos regresar
 
shordi - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Mostrar mensajes anteriores:    
 

Publicar nuevo tema  Responder al tema  Página 1 de 1
 

Usuarios navegando en este tema: 0 registrados, 0 ocultos y 1 invitado
Usuarios registrados conectados: Ninguno


 
Lista de permisos
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



  

 

cron