Page 1 of 1

brush with jpeg file

Posted: Tue Jan 02, 2007 9:55 am
by areang
Hi, Mr. Antonio/Mr. Enrico

Can I use JPEG file for BRUSH ?

thank's
Regards
Areang

Re: brush with jpeg file

Posted: Tue Jan 02, 2007 11:13 am
by Enrico Maria Giordano
Yes, but you would have to modify TBrush classes:

Code: Select all

      case cBmpFile != nil
           if File( cBmpFile )
              ::hBitMap = ReadBitmap( 0, cBmpFile )
              ::hBrush = If( ::hBitmap != 0, CreatePatternBrush( ::hBitmap ), )
           endif
You should use FreeImage.dll instead of ReadBitmap() to load the bitmap.

EMG

Posted: Tue Jan 02, 2007 4:03 pm
by Kleyber
Hi Enrico,

That's interesting. You know i am using Freeimage in my apps, but I didn't realize that! Can you post a small example of putting a JPG file as a brush using Freeimage?

Regards,

Posted: Tue Jan 02, 2007 4:41 pm
by Enrico Maria Giordano
Here it is:

Code: Select all

#include "Fivewin.ch"


STATIC hLib


FUNCTION MAIN()

    LOCAL oDlg, oBrush

    DEFINE BRUSH oBrush FILENAME "test.jpg"

    DEFINE DIALOG oDlg;
           BRUSH oBrush

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


#define CBM_INIT 4

#define DIB_RGB_COLORS 0


FUNCTION FILOADIMG( cFile )

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

    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 )
    hInfoH  = FIGETINFOHEADER( hDib )
    hInfo   = FIGETINFO( hDib )
    hBits   = FIGETBITS( hDib )
    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 )

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

#ifdef __CLIPPER__
    hBmp = NLOWORD( WOWHANDLE16( hBmp, 8 ) )
#endif

    RETURN hBmp


FUNCTION FISAVEIMG( cSrcFile, cDstFile, nDstFormat, nQuality )

    LOCAL nSrcFormat, hDib, hDib2, lOk

    DEFAULT nQuality := 0

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

    nSrcFormat = FIGETFILETYPE( cSrcFile, 0 )

    hDib = FILOAD( nSrcFormat, cSrcFile, 0 )

    hDib2 = FICNV24( hDib )

    lOk = FISAVE( nDstFormat, hDib2, cDstFile, nQuality )

    FIUNLOAD( hDib )
    FIUNLOAD( hDib2 )

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

    RETURN lOk

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

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 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 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 FICNV24( hDib AS LONG ) AS LONG;
      PASCAL FROM "_FreeImage_ConvertTo24Bits@4" 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"

//----------------------------------------------------------------------------//
This is the change in TBrush:New():

Code: Select all

      case cBmpFile != nil
           if File( cBmpFile )
              ::hBitMap = FILoadImg( cBmpFile )
//              ::hBitMap = ReadBitmap( 0, cBmpFile )
              ::hBrush = If( ::hBitmap != 0, CreatePatternBrush( ::hBitmap ), )
           endif
EMG

Posted: Tue Jan 02, 2007 5:33 pm
by Kleyber
Fantastic!! Thanks a lot, Enrico.

Regards,

a question

Posted: Tue Jan 02, 2007 8:04 pm
by fleal
hi guys,
a question. Where's the freeimage.dll for xharbour or harbour ??

Thanks
Fernando

Re: a question

Posted: Tue Jan 02, 2007 8:09 pm
by Enrico Maria Giordano
fleal wrote:hi guys,
a question. Where's the freeimage.dll for xharbour or harbour ??

Thanks
Fernando
Being a DLL, FreeImage is compiler independent.

EMG

Posted: Wed Jan 03, 2007 1:26 pm
by Kleyber
Enrico,

I was observing when I use this with Dialogs, it's all ok with JPG files, but with Window it only works if the image is BMP format. Why can't I use with Windows?

Regards,

Posted: Wed Jan 03, 2007 1:40 pm
by Enrico Maria Giordano
The following sample using a WINDOW works fine here:

Code: Select all

FUNCTION MAIN()

    LOCAL oWnd, oBrush

    DEFINE BRUSH oBrush FILENAME "xsnow.gif"

    DEFINE WINDOW oWnd;
           BRUSH oBrush

    ACTIVATE WINDOW oWnd

    RETURN NIL
EMG

Posted: Wed Jan 03, 2007 2:29 pm
by Kleyber
Enrico,

Thanks for your answer. I'll try it again. maybe it's because of my FWH version (2.5).

regards,

Posted: Thu Jan 04, 2007 2:27 am
by areang
Mr. Enrico

Thank's
See to next my questions

Regards
Areang