Page 3 of 3

Re: How to display TIF picture ?

Posted: Mon Nov 23, 2009 9:05 am
by gfilatov
Roberto Lopez wrote:
gfilatov wrote: I've adapted this sample for HMG 3.0 already.
Take a look for attached working demo with project files and needed library ;)
I'm asking your permission to include this sample in the next HMG test build.
Hi Roberto,

Many thanks for your request :!:

You have my permission, of course.

Please take a look for the updated source of this sample below :arrow:

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2009 Roberto Lopez <harbourminigui@gmail.com>
 * http://harbourminigui.googlepages.com/
 *
 * FreeImage.dll should present to use this sample
 * http://freeimage.sourceforge.net/
 *
 * Copyright 2003-2009 Grigory Filatov <gfilatov@freemail.ru>
*/

#include "FreeImage.ch"

#include "minigui.ch"

#define PROGRAM 'FreeImage Viewer Lite'
#define VERSION ' version 1.4.0'
#define COPYRIGHT ' 2003-2008 Grigory Filatov'

#define MsgAlert( c ) MsgStop( c, "Attention" )

Static handle, nWidth, nHeight, nKoef := 1

Function Main( fname )

   default fname := "test.tif"

   IF !FILE('FreeImage.Dll')
      MsgAlert("Can't found the FreeImage.Dll")
      Return Nil
   ENDIF

   fi_Initialise()

   SET CENTURY ON
   SET DATE GERMAN

   DEFINE WINDOW Form_Main ;
	AT 0,0 ;
	WIDTH 400 HEIGHT 600 ;
	TITLE PROGRAM ;
	MAIN ;
	ON INIT {|| handle := FI_Load( FIF_TIFF, fname, TIFF_DEFAULT ), ;
		nWidth := FI_GetWidth( handle ), nHeight := FI_GetHeight( handle ), ;
		Form_Main.Width  := nWidth + GetBorderWidth() + 4, ;
		Form_Main.Height := nHeight + GetBorderHeight() + GetTitleHeight() + 4, ;
		PaintWindow( 'Form_Main' ) } ;
	ON PAINT PaintWindow( 'Form_Main' ) ;
	ON MOUSECLICK MsgAbout() ;
	ON RELEASE fi_Deinitialise() ;
	FONT 'MS Sans Serif' SIZE 9

   END WINDOW

   CENTER WINDOW Form_Main

   ACTIVATE WINDOW Form_Main

Return Nil

Static Function PaintWindow( Window )
   Local i := GetFormIndex ( Window )
   Local FormHandle := _HMG_SYSDATA [ 67  ] [i] 
   Local hDC := GetDC( FormHandle )

   IF handle == Nil
      Return -1
   ENDIF

   FI_WinDraw( handle, hDC, 0, 0, Round( nHeight * nKoef, 0 ), Round( nWidth * nKoef, 0 ) )

   ReleaseDC( FormHandle, hDC )

Return 0

Static Function MsgAbout()
return MsgInfo( padc(PROGRAM + VERSION, 40) + CRLF + ;
	padc("Copyright " + Chr(169) + COPYRIGHT, 40) + CRLF + CRLF + ;
	hb_compiler() + CRLF + version() + CRLF + ;
	Left(MiniGuiVersion(), 36) + CRLF + ;
	"FreeImage.dll version: "+FI_GetVersion() + CRLF + CRLF + ;
	padc("This program is Freeware!", 40), "About..." )
Veritas Filia Temporis

Re: How to display TIF picture ?

Posted: Mon Nov 23, 2009 4:30 pm
by Ricci
Hello Grigory !

You need a FI_Unload to clear the bitmap memory. Forgetting that will cause the program to stop loading TIF images after it displayed about 100 of them.

From the FreeImage documentation:
FreeImage_Unload
DLL_API void DLL_CALLCONV FreeImage_Unload(FIBITMAP *dib);
Deletes a previously loaded FIBITMAP from memory.
You always need to call this function once you’re done with a bitmap, or you will have a memory leak.

Regards ... Ricci

Code: Select all

   
....
FI_WinDraw( handle, hDC, 0, 0, Round( nHeight * nKoef, 0 ), Round( nWidth * nKoef, 0 ) )

FI_UnLoad (handle)   // <===

ReleaseDC( FormHandle, hDC )
...

Re: How to display TIF picture ?

Posted: Tue Nov 24, 2009 3:39 am
by Roberto Lopez
gfilatov wrote: Hi Roberto,

Many thanks for your request :!:

You have my permission, of course.

Please take a look for the updated source of this sample below
Thanks!

I'll do.