Rotate Image with freeimage.dll

Rotate Image with freeimage.dll

Postby Silvio.Falconi » Sat Oct 05, 2013 9:49 am

I found this function and I insert it on Image.prg class

Code: Select all  Expand view
DLL32 STATIC FUNCTION FIRotate ( hDib AS LONG, nAngle AS _DOUBLE ) AS LONG;
       PASCAL FROM "_FreeImage_RotateClassic@12" LIB If( IsWin64(), "freeImage64.dll", "freeImage.dll" )

DLL32 STATIC FUNCTION FIRotateEX ( hDib AS LONG, nAngle AS _DOUBLE, x_Shift AS _DOUBLE,y_Shift AS _DOUBLE,;
                                 x_Orig AS _DOUBLE, y_Orig AS _DOUBLE, lMask AS BOOL ) AS LONG;
      PASCAL FROM "_FreeImage_RotateEx@48" LIB If( IsWin64(), "freeImage64.dll", "freeImage.dll" )



on test sample I insert a combobox

@ 240,oDlg:nWidth-120 COMBOBOX oRotate VAR nRotate ;
ITEMS {"90","180","270","360"} ;
OF oDlg FONT oFnt PIXEL SIZE 35,200 ;
ON CHANGE FIRotate(oImage,nRotate)


but it make error

Error: Unresolved external '_HB_FUN_FIROTATE' referenced from F:\GALLERIA\OBJ\TEST.OBJ


any solution ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Rotate Image with freeimage.dll

Postby nageswaragunupudi » Sun Oct 06, 2013 1:31 pm

Please remove STATIC from DLL statement.

STATIC means the function is available to be used only in that module.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Rotate Image with freeimage.dll

Postby Silvio.Falconi » Sun Oct 06, 2013 2:09 pm

same
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Rotate Image with freeimage.dll

Postby George » Sun Oct 06, 2013 6:20 pm

Silvio,

Review the below code found in the forum.

Code: Select all  Expand view
//------------------ Freeimage.dll ------------------------//
FUNCTION SaveImage( cFile )
LOCAL nFormat, hDib, hInfoH, hInfo, hBits, hWnd, hDC, hBmp, lOk

#ifdef __CLIPPER__
    hLib = LOADLIB32( "freeimage.dll" )
#else
    hLib = LOADLIBRARY( "freeimage.dll" )
#endif

    if hLib <= 32
        MsgStop( "Cannot load FreeImage.dll" )
        return 0
    endif

    nFormat := FIGETFILETYPE( cFile, 0 )
    hDib    := FILOAD( nFormat, cFile, 0 )
    hInfoH  := FIGETINFOHEADER( hDib )
    hInfo   := FIGETINFO( hDib )
    hBits   := FIGETBITS( hDib )
    hWnd    := GETDESKTOPWINDOW()

#ifdef __CLIPPER__
    hDC = GETDC32( hWnd )
#else
    hDC = GETDC( hWnd )
#endif

lOk := fiSave( 2 , hDib, cFile )

hBmp = CREATEDIBITMAP( hDC, hInfoH, CBM_INIT, hBits, hInfo, DIB_RGB_COLORS )

#ifdef __CLIPPER__
    RELEASEDC32( hWnd, hDC )
#else
    RELEASEDC( hWnd, hDC )
#endif

FIUNLOAD( hDib )

#ifdef __CLIPPER__
    FREELIB32( hLib )
#else
    FREELIBRARY( hLib )
#endif
RETURN hBmp



DLL32 STATIC FUNCTION FIGETFILETYPE( cFileName AS LPSTR, nSize AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_GetFileType@8" LIB hLib

DLL32 STATIC FUNCTION FILOAD( nFormat AS LONG, cFileName AS LPSTR, nFlags AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_Load@12" LIB hLib

DLL32 STATIC FUNCTION FIUNLOAD( hDib AS LONG ) AS VOID;
      PASCAL FROM "_FreeImage_Unload@4" LIB hLib

DLL32 STATIC FUNCTION FIGETINFOHEADER( hDib AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_GetInfoHeader@4" LIB hLib

DLL32 STATIC FUNCTION FIGETINFO( hDib AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_GetInfo@4" LIB hLib

DLL32 STATIC FUNCTION FIGETBITS( hDib AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_GetBits@4" LIB hLib

DLL32 STATIC FUNCTION FISAVE( nFormat AS LONG, hDib AS LONG, cFileName AS LPSTR, nFlags AS LONG ) AS BOOL;
      PASCAL FROM "_FreeImage_Save@16" LIB hLib

DLL32 STATIC FUNCTION FIROTATE( hDib AS LONG, nAngle AS _DOUBLE ) AS LONG;
      PASCAL FROM "_FreeImage_RotateClassic@12" LIB hLib

DLL32 STATIC FUNCTION GETDC32( hWnd AS LONG ) AS LONG;
      PASCAL FROM "GetDC" LIB "user32.dll"

DLL32 STATIC FUNCTION RELEASEDC32( hWnd AS LONG ) AS LONG;
      PASCAL FROM "ReleaseDC" LIB "user32.dll"

DLL32 STATIC FUNCTION CREATEDIBITMAP( hDC AS LONG, hInfoH AS LONG, nFlags AS LONG, hBits AS LONG, hInfo AS LONG, nUsage AS LONG ) AS LONG;
      PASCAL FROM "CreateDIBitmap" LIB "gdi32.dll"

DLL32 FUNCTION WOWHANDLE16( nHandle AS LONG, nHandleType AS LONG ) AS LONG;
      PASCAL FROM "WOWHandle16" LIB "wow32.dll"

DLL32 FUNCTION TWAIN_AcquireToClipboard (hwndApp As LONG, wPixTypes as CHAR );
     AS LONG PASCAL FROM TWAIN_AcquireToClipboard Lib "EZTW32.DLL"

/*
'  Like AcquireNative, but puts the resulting image, if any, into the system
'  clipboard.  Under Windows, this will put a CF_DIB item in the clipboard
'  if successful.  If this call fails, the clipboard is either empty or
'  contains the old contents.
'  A return value of 1 indicates success, 0 indicates failure.
'
'  Useful for environments like Visual Basic where it is hard to make direct
'  use of a DIB handle.  In fact, TWAIN_AcquireToClipboard uses
'  TWAIN_AcquireNative for all the hard work.
 */

 //=======================================================================
FUNCTION fRotaImage( cFile )
LOCAL nFormat, hDib, hInfoH, hInfo, hBits, hWnd, hDC, hBmp, lOk
LOCAL cFileNew, nLenJPG, nLenJPGNew

#ifdef __CLIPPER__
    hLib = LOADLIB32( "freeimage.dll" )
#else
    hLib = LOADLIBRARY( "freeimage.dll" )
#endif

    if hLib <= 32
        MsgStop( "Cannot load FreeImage.dll" )
        return 0
    endif

    nFormat := FIGETFILETYPE( cFile, 0 )
    hDib    := FILOAD( nFormat, cFile, 0 )
    hInfoH  := FIGETINFOHEADER( hDib )
    hInfo   := FIGETINFO( hDib )
    hBits   := FIGETBITS( hDib )
    hWnd    := GETDESKTOPWINDOW()

#ifdef __CLIPPER__
    hDC = GETDC32( hWnd )
#else
    hDC = GETDC( hWnd )
#endif

nFiRotate := FIROTATE( @hDib, 90 )

lOk := fiSave( 2 , nFiRotate, cFile )

hBmp = CREATEDIBITMAP( hDC, hInfoH, CBM_INIT, hBits, hInfo, DIB_RGB_COLORS )

#ifdef __CLIPPER__
    RELEASEDC32( hWnd, hDC )
#else
    RELEASEDC( hWnd, hDC )
#endif

RETURN NIL
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Rotate Image with freeimage.dll

Postby MaxP » Mon Oct 07, 2013 6:12 am

Ok
other solution

I wrote this code in image.prg

Code: Select all  Expand view

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

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

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

static function FIROTATEIMG( cSrcFile, nAngle )

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

   #ifdef __CLIPPER__
      hLib = LoadLib32( "freeimage.dll" )
   #else
      hLib = LoadLibrary( "freeimage.dll" )
   #endif

   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          

   #ifdef __CLIPPER__
      FreeLib32( hLib )
   #else
      FreeLibrary( hLib )
   #endif

return hBmp


DLL32 STATIC FUNCTION FIRotate ( hDib AS LONG, nAngle AS _DOUBLE ) AS LONG;
      PASCAL FROM "_FreeImage_RotateClassic@12" LIB hLib
 


in your code

Code: Select all  Expand view

@ 240,oDlg:nWidth-120 COMBOBOX oRotate VAR nRotate ;
ITEMS {"90","180","270","360"} ;
OF oDlg FONT oFnt PIXEL SIZE 35,200 ;
ON CHANGE oImage:Rotate( nRotate )
 


Massimo
User avatar
MaxP
 
Posts: 85
Joined: Thu Jul 12, 2007 2:02 pm

Re: Rotate Image with freeimage.dll

Postby Silvio.Falconi » Mon Oct 07, 2013 6:00 pm

Massimo ,
the image is not rotating

and make error on METHOD Progress (lProgress)

pleaee try it
Code: Select all  Expand view

#include "FiveWin.ch"
#include "Image.ch"

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

function Main()
   LOCAL        oWnd, oImage
    Local oRotate, nRotate


   DEFINE WINDOW oWnd FROM 0, 0 TO 22, 60 ;
      TITLE FWDESCRIPTION + " JPG,JIF,GIF,BMP,DIB,RLE,TGA,PCX support!"

   @ 0, 0 IMAGE oImage SIZE 300, 300 OF oWnd SCROLL ADJUST

 *  oImage:Progress( .f. )

   @ 2, 56 BUTTON "Select Image" SIZE 100,20 OF oWnd ACTION GetImage( oImage )

   @ 4, 56 BUTTON "Print" SIZE 100,20 OF oWnd ACTION PrintImage( oImage )

   @ 6, 56 BUTTON "Copy" SIZE 100, 20 OF oWnd ;
      ACTION oImage:CopyToClipboard()

   @ 8, 56 BUTTON "Paste" SIZE 100, 20 OF oWnd ;
      ACTION ( oImage:LoadFromClipboard(), oImage:Refresh() )

   @ 10, 56 BUTTON "Save" SIZE 100, 20 OF oWnd ;
      ACTION ( oImage:SaveImage( "SAVED.JPG", 2, 25 ), MsgInfo( "saved as saved.jpg" ) )

   @ 12, 56 BUTTON "Exit" SIZE 100, 20 OF oWnd ACTION oWnd:End()
   
   @ 20, 56 CHECKBOX oImage:lStretch PROMPT "Stretch" SIZE 100, 20 OF oWnd ;
      ON CHANGE ( oImage:ScrollAdjust(), oImage:Refresh() )


   @ 20,46 COMBOBOX oRotate VAR nRotate ;
                        ITEMS {"0","60","90","180","270"} ;
                         OF oWnd   SIZE 35,200 ;
                         ON CHANGE (oImage:RotateImage( nRotate ),oImage:refresh())




   ACTIVATE WINDOW oWnd  ON DROPFILES TakeDrop( aFiles, oImage )

return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Rotate Image with freeimage.dll

Postby Silvio.Falconi » Mon Oct 07, 2013 6:35 pm

if I rem Progress run ok

@ 240,oDlg:nWidth-120 COMBOBOX oRotate VAR nRotate ;
ITEMS {"60","90","180","270","360"} ;
OF oDlg FONT oFnt PIXEL SIZE 35,200 ;
ON CHANGE (oImage:RotateImage( val(nRotate) ),oImage:refresh())


the problem is when I rotate the image the image is smaller and make a black background, if I try to return to first position I have problems and then the image is too small

Image

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Rotate Image with freeimage.dll

Postby ukoenig » Tue Oct 08, 2013 12:29 pm

Silvio,

after loading a image, save the original position.
Before using ROTATE, restore the original.

@ 2, 106 BUTTON "Select Image" SIZE 100,20 OF oWnd ;
ACTION ( GetImage( oImage ), oImage:CopyToClipboard() )


@ 250, oWnd:nWidth-120 COMBOBOX oRotate VAR nRotate ;
ITEMS {"60","90","180","270","360"} ;
OF oWnd FONT oFont PIXEL SIZE 50,200 ;
ON CHANGE ( oImage:LoadFromClipboard(), ;
oImage:RotateImage( val(nRotate) ), oImage:refresh() )

Image

Image

Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 90 guests