brush with jpeg file

brush with jpeg file

Postby areang » Tue Jan 02, 2007 9:55 am

Hi, Mr. Antonio/Mr. Enrico

Can I use JPEG file for BRUSH ?

thank's
Regards
Areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Re: brush with jpeg file

Postby Enrico Maria Giordano » Tue Jan 02, 2007 11:13 am

Yes, but you would have to modify TBrush classes:

Code: Select all  Expand view  RUN
      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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Kleyber » Tue Jan 02, 2007 4:03 pm

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,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Postby Enrico Maria Giordano » Tue Jan 02, 2007 4:41 pm

Here it is:

Code: Select all  Expand view  RUN
#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  Expand view  RUN
      case cBmpFile != nil
           if File( cBmpFile )
              ::hBitMap = FILoadImg( cBmpFile )
//              ::hBitMap = ReadBitmap( 0, cBmpFile )
              ::hBrush = If( ::hBitmap != 0, CreatePatternBrush( ::hBitmap ), )
           endif


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

Postby Kleyber » Tue Jan 02, 2007 5:33 pm

Fantastic!! Thanks a lot, Enrico.

Regards,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

a question

Postby fleal » Tue Jan 02, 2007 8:04 pm

hi guys,
a question. Where's the freeimage.dll for xharbour or harbour ??

Thanks
Fernando
fleal
 
Posts: 234
Joined: Tue Oct 25, 2005 12:39 am
Location: México, DF

Re: a question

Postby Enrico Maria Giordano » Tue Jan 02, 2007 8:09 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Kleyber » Wed Jan 03, 2007 1:26 pm

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,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Postby Enrico Maria Giordano » Wed Jan 03, 2007 1:40 pm

The following sample using a WINDOW works fine here:

Code: Select all  Expand view  RUN
FUNCTION MAIN()

    LOCAL oWnd, oBrush

    DEFINE BRUSH oBrush FILENAME "xsnow.gif"

    DEFINE WINDOW oWnd;
           BRUSH oBrush

    ACTIVATE WINDOW oWnd

    RETURN NIL


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

Postby Kleyber » Wed Jan 03, 2007 2:29 pm

Enrico,

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

regards,
Kleyber Derick

FWH / xHb / xDevStudio / SQLLIB
User avatar
Kleyber
 
Posts: 581
Joined: Tue Oct 11, 2005 11:28 am
Location: São Luiz, Brasil

Postby areang » Thu Jan 04, 2007 2:27 am

Mr. Enrico

Thank's
See to next my questions

Regards
Areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 55 guests