Freeimage

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Freeimage

Post by sudip »

Hello,

How can I use Freeimage library with HMG 3.0.35 ? I found there is a library hmg\harbour\lib\libhbfimage.a

But, when I use this library, got some undefined functions errors during compilation and linking.

I need it to store images to tables, after reducing the size of image. Without reducing the image size, table size is increasing very much.

Thanks in advance.
With best regards,
Sudip
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Freeimage

Post by Ricci »

Yes you can use it but .... it seems like not all Freeimage functions are supported via the libhbfimage.a or the functions call maybe different to the Freeimage documentation.

- you should include freeimage.ch

- you should include this code at the beginning of your program

Code: Select all

   IF !FILE('FreeImage.Dll')
      MsgAlert("Can't found the FreeImage.Dll")
      Return Nil
   ENDIF
   fi_Initialise()
- and a *.hbc file is recommended (assuming you have a subdir called lib under your program dir containing the file libfreeimage.a)

Code: Select all

incpaths=
libpaths=lib
libs=FreeImage
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: Freeimage

Post by sudip »

Thanks a lot Ricci. I created following function as follows:

Code: Select all

#define STD_WIDTH    123
#define STD_HEIGHT   123

// Following function is used to reduce the image size
// This will be useful for storing large image file into memo field
// This will reduce table size to a great extent :-) Sudip
Function ImageCompress(cFile)
   local isJpg := .f., isBmp := .f., isGif := .f.
   local cStr, im, rescale, mHeight, mWidth


   do case
      case upper(right(cFile, 3)) == "JPG"
         isJpg := .t.
      case upper(right(cFile, 3)) == "BMP"
         isBmp := .t.
      case upper(right(cFile, 3)) == "GIF"
         isGif := .t.
      otherwise
         return ""
   endcase
   
   cStr := MemoRead(cFile)
   
   im := FI_LoadFromMem( if(isJpg, FIF_JPEG, if(isBmp, FIF_BMP, FIF_GIF)), cStr, JPEG_DEFAULT )
   
   mWidth := fi_GetWidth( im )
   mHeight := fi_GetHeight( im )
   
   if mWidth > STD_HEIGHT
      rescale := fi_Rescale( im, mWidth * (STD_HEIGHT / mHeight), STD_HEIGHT, FILTER_BICUBIC )
      cTemp := TempFileName()
      fi_Save( FIF_JPEG, rescale, cTemp, JPEG_DEFAULT )
      cStr := MemoRead(cTemp)
      fi_unload( rescale )
      filedelete( cTemp )
   endif
   
   fi_Unload( im )
   
   return (cStr)


FUNCTION TempFileName()
   LOCAL nFileHandle
   LOCAL cFileName := ""
   
   nFileHandle := HB_FTempCreate( ,,, @cFileName )

   IF nFileHandle > 0
      FClose( nFileHandle )
   ENDIF
   
   RETURN cFileName
I have some problem with it.
Ok I shall wait for HMG.4. It will be the software tool of my dream :D
With best regards,
Sudip
Post Reply