Portrait vs Landscape Image

Portrait vs Landscape Image

Postby Ollie » Fri Jul 13, 2007 2:51 pm

If a picture was taken Portrait, can I rotate it to display correctly with FiveWin?
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Ollie
 
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Re: Portrait vs Landscape Image

Postby Enrico Maria Giordano » Fri Jul 13, 2007 3:01 pm

This is a sample using FreeImage.dll or LibGfl.dll:

Code: Select all  Expand view
#include "Fivewin.ch"


STATIC hLib, hLibGFL


FUNCTION MAIN()

    LOCAL oWnd, hBmp

    DEFINE WINDOW oWnd

//    hBmp = GFLLOADIMG( "IMAGE.JPG", 80, 50, 90 )
    hBmp = FILOADIMG( "IMAGE.JPG", 90 )

    ACTIVATE WINDOW oWnd;
             ON PAINT MYBKGRND( oWnd, hDC, hBmp );
             MAXIMIZED

    IF hBmp != 0; DELETEOBJECT( hBmp ); ENDIF

    RETURN NIL


STATIC FUNCTION MYBKGRND( oWnd, hDC, hBmp )

    LOCAL nTop    := ( oWnd:nHeight() - NBMPHEIGHT( hBmp ) ) / 2
    LOCAL nLeft   := ( oWnd:nWidth() - NBMPWIDTH( hBmp ) ) / 2
    LOCAL nWidth  := NBMPWIDTH( hBmp )
    LOCAL nHeight := NBMPHEIGHT( hBmp )

    IF hBmp = 0; RETURN NIL; ENDIF

    PALBMPDRAW( hDC, nTop, nLeft, hBmp, , nWidth, nHeight )

    RETURN NIL


#define CBM_INIT 4

#define DIB_RGB_COLORS 0


FUNCTION FILOADIMG( cFile, nAngle )

    LOCAL nFormat, hDib, hDibR, hInfoH, hInfo, hBits, hWnd, hDC, hBmp

    DEFAULT nAngle := 0

    IF UPPER( CFILEEXT( cFile ) ) = "BMP"
        RETURN READBITMAP( 0, cFile )
    ENDIF

#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 )
    hDibR   = FIROTATE( hDib, nAngle )
    hInfoH  = FIGETINFOHEADER( hDibR )
    hInfo   = FIGETINFO( hDibR )
    hBits   = FIGETBITS( hDibR )
    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( hDib )
    FIUNLOAD( hDibR )

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

#ifdef __CLIPPER__
    hBmp = NLOWORD( WOWHANDLE16( hBmp, 8 ) )
#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 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"


#include "Struct.ch"


STATIC FUNCTION GFLLOADIMG( cFile, nWidth, nHeight, nAngle )

    LOCAL oGflLoadParams := OGFLLOADPARAMS()

    LOCAL cBuffer

    LOCAL hBitmap := 0, hBitmapR := 0, hBmp := 0

    hLibGFL = LOADLIB32( "libgfl254.dll" )

    GFLLIBINIT()

    GFLENABLELZW( 1 )

    cBuffer = oGflLoadParams:cBuffer

    GFLGETDEFPARAMS( @cBuffer )

    oGflLoadParams:cBuffer = cBuffer

    GFLLOADTHUMBNAIL( cFile, nWidth, nHeight, @hBitmap, oGflLoadParams:cBuffer, 0 )

    IF hBitmap = 0; RETURN 0; ENDIF

    GFLROTATE( hBitmap, @hBitmapR, nAngle, 0 )

    IF hBitmapR = 0; RETURN 0; ENDIF

    GFLCONVERTBITMAPINTODDB( hBitmapR, @hBmp )

    GFLFREEBITMAPDATA( hBitmap )
    GFLFREEBITMAPDATA( hBitmapR )

    GFLLIBEXIT()

    FREELIB32( hLibGFL )

    RETURN hBmp


STATIC FUNCTION OGFLLOADPARAMS()

    LOCAL oGflLoadParams

    STRUCT oGflLoadParams
        MEMBER nFlags     AS DWORD
        MEMBER nFormatInd AS LONG
        MEMBER nImageWant AS LONG
        MEMBER nOrigin    AS WORD
        MEMBER nClrModel  AS WORD
        MEMBER nLinePad   AS DWORD
        MEMBER nDefAlpha  AS BYTE
        MEMBER nNoAlpha   AS BYTE
        MEMBER nPngComp   AS BYTE
        MEMBER nWMFHiRes  AS BYTE
        MEMBER nWidth     AS LONG
        MEMBER nHeight    AS LONG
        MEMBER nOffset    AS DWORD
        MEMBER nChanOrder AS WORD
        MEMBER nChanType  AS WORD
        MEMBER nPcdBase   AS WORD
        MEMBER nEpsDpi    AS WORD
        MEMBER nEpsWidth  AS LONG
        MEMBER nEpsHeight AS LONG
        MEMBER nLutType   AS WORD
        MEMBER nReserved3 AS WORD
        MEMBER nLutData   AS DWORD
        MEMBER nLutFName  AS DWORD
        MEMBER nAutoBal   AS BYTE
        MEMBER nCameraBal AS BYTE
        MEMBER nReserved4 AS WORD
        MEMBER nRowGamma  AS DWORD
        MEMBER nRowBright AS DWORD
        MEMBER nRowRedSca AS DWORD
        MEMBER nRowBluSca AS DWORD
        MEMBER nRowFltDom AS DWORD
        MEMBER nRowFltRng AS DWORD
        MEMBER nRead      AS DWORD
        MEMBER nTell      AS DWORD
        MEMBER nSeek      AS DWORD
        MEMBER nAllocBmp  AS DWORD
        MEMBER nAllocPrm  AS DWORD
        MEMBER nProgress  AS DWORD
        MEMBER nProgPrm   AS DWORD
        MEMBER nWantCan   AS DWORD
        MEMBER nWantPrm   AS DWORD
        MEMBER nUserPrm   AS DWORD
    ENDSTRUCT

    RETURN oGflLoadParams


DLL32 STATIC FUNCTION GFLLIBINIT() AS LONG;
      PASCAL FROM "gflLibraryInit" LIB hLibGFL

DLL32 STATIC FUNCTION GFLLIBEXIT() AS VOID;
      PASCAL FROM "gflLibraryExit" LIB hLibGFL

DLL32 STATIC FUNCTION GFLENABLELZW( nEnable AS LONG ) AS VOID;
      PASCAL FROM "gflEnableLZW" LIB hLibGFL

DLL32 STATIC FUNCTION GFLGETDEFPARAMS( @cLoadParams AS LPSTR ) AS VOID;
      PASCAL FROM "gflGetDefaultLoadParams" LIB hLibGFL

DLL32 STATIC FUNCTION GFLLOADTHUMBNAIL( cFileName AS LPSTR, nWidth AS LONG, ;
                       nHeight AS LONG, @hBitmap AS PTR, cLoadParams AS LPSTR, cInformation AS LPSTR ) AS LONG;
      PASCAL FROM "gflLoadThumbnail" LIB hLibGFL

DLL32 STATIC FUNCTION GFLROTATE( hBitmapSource AS PTR, @hBitmapDest AS PTR, nAngle AS LONG, nColor AS LONG ) AS LONG;
      PASCAL FROM "gflRotate" LIB hLibGFL

DLL32 STATIC FUNCTION GFLFREEBITMAPDATA( hBitmap AS PTR ) AS VOID;
      PASCAL FROM "gflFreeBitmapData" LIB hLibGFL

DLL32 STATIC FUNCTION GFLCONVERTBITMAPINTODDB( hBitmap AS PTR, @hBmp AS PTR ) AS LONG;
      PASCAL FROM "gflConvertBitmapIntoDDB" LIB "libgfle254.dll"


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 28 guests