Page 1 of 1

Rotar imagen Error solo en 64 bits

Posted: Sun Apr 24, 2016 6:59 pm
by luisduque
Saludos.

Necesito rotar una imagen, con Gdiplus lo hace bien y con freeimage también lo hace bien, pero en win64 bits en ambos casos da error

Ejemplo que funciona bien

Code: Select all | Expand


// Testing

#include "FiveWin.ch"

function Main()
Local oImg
   Local nFlags   := nOr( OFN_PATHMUSTEXIST , OFN_NOCHANGEDIR , ;
                     OFN_ALLOWMULTISELECT , OFN_EXPLORER , ;
                     OFN_LONGNAMES )
   Local cImg
   cImg := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Seleciona una Imagen", 4,, .f., .t., nFlags )

            //Forma 1
            oImg:= GDIBmp():new( cImg )
           oImg:Rotate( 3 ) //Rota 270 grados
           oImg:Save( "Imagen1.bmp" ) //imagen ya rotada
           oImg:End()

            //Forma 2
           Define Image oImg FileName cImg
              oImg:RotateImage( 270 ) //Rota 270 grados
              oImg:SaveImage( "Imagen2.bmp", 0, 0 )  //imagen ya rotada
           oImg:End()


return nil

//------------------------------------------------------------------------//

procedure appsys // XBase++ requirement
return

 



Hay que tener en cuenta que para freeimage modifique el image.prg agregando el metodo de rotación

METHOD RotateImage( nAngle )
.....

Code: Select all | Expand


METHOD RotateImage( nAngle ) CLASS TImage
   local hDib := DibFromBitmap( ::hBitmap )
   local cTempFile := cTempFile( , "BMP" )
   local lSaved, hBmp
   local hOldBmp  := ::hBitmap
   local hOldPal  := ::hPalette

   DibWrite( cTempFile, hDib )

   GloBalFree( hDib )
   
   hBmp := FIROTATEIMG( cTempFile, nAngle )

   FErase( cTempFile )
   
   IF hBmp != 0
      if ! Empty( hOldBmp )
          PalBmpFree( hOldBmp, hOldPal )
      endif
           
      ::hBitmap := hBmp
       
      PalBmpNew( ::hWnd, ::hBitmap, ::hPalette )
       
      ::Refresh()
   ENDIF  
return nil
 



Agregue la funcion

Code: Select all | Expand



Function FIROTATEIMG( cSrcFile, nAngle )

   local nSrcFormat, hDib, hDib2, lOk
   local nFormat, hInfoH, hInfo, hBits, hWnd, hDC, hBmp := 0

   nSrcFormat = FIGETFILETYPE( cSrcFile, 0 )

   hDib = FILOAD( nSrcFormat, cSrcFile, 0 )

   IF hDib <> 0
      hDib2 = FIRotate( hDib, nAngle )
       
      IF hDib2 <> 0
         hInfoH  = FIGETINFOHEADER( hDib2 )
         hInfo   = FIGETINFO( hDib2 )
         hBits   = FIGETBITS( hDib2 )
         hWnd    = GETDESKTOPWINDOW()
                   
         #ifdef __CLIPPER__
             hDC = GETDC32( hWnd )
         #else
             hDC = GETDC( hWnd )
         #endif
                   
         hBmp = CreateDiBitmap( hDC, hInfoH, CBM_INIT, hBits, hInfo, DIB_RGB_COLORS )

          #ifdef __CLIPPER__
          ReleaseDC32( hWnd, hDC )
        #else
            ReleaseDC( hWnd, hDC )
          #endif
                   
         FIUNLOAD( hDib2 )
      ENDIF  
       
      FIUNLOAD( hDib )
   ENDIF          

return hBmp
 


y por ultimo

Code: Select all | Expand


DLL32 FUNCTION FIRotate( hDib AS LONG, nAngle AS _DOUBLE ) AS LONG;
      PASCAL FROM If( IsExe64(), "FreeImage_Rotate", "_FreeImage_Rotate@16" ) ;
      LIB hLib
 



Toda esta información está en los foros

Actualmente trabajo con
Fivewin 15.09
Harbour 3.2.0
Visual Studio 2013
MariaDb/MySql


Gracias.

Re: Rotar imagen Error solo en 64 bits

Posted: Sun Apr 24, 2016 10:22 pm
by Antonio Linares
Luis,

He añadido ese método a la Clase TImage para la próxima versión de FWH y he realizado unos cambios en la función FWCallDll() para que soporte el parámetro DOUBLE correctamente.

Te he enviado las nuevas librerias por email

Gracias!

Re: Rotar imagen Error solo en 64 bits

Posted: Mon Apr 25, 2016 3:10 am
by carlos vargas
Antonio, una pregunta, actualmente tanto harbour como xharbour, las funciones loadlibrary y freelibrary trabajan con punteros en lugar de numéricos, no sera posible ir pensando en una fwLoadLibrary y fwFreeLibrary para no colicionar con las nativas de los compiladores.

Re: Rotar imagen Error solo en 64 bits

Posted: Mon Apr 25, 2016 6:18 am
by Antonio Linares
Carlos,

Si, tienes razón.

gracias