How to display TIF picture ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
gfilatov
Posts: 552
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 14 times
Been thanked: 121 times
Contact:

Re: How to display TIF picture ?

Post by gfilatov » Mon Nov 23, 2009 9:05 am

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
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Post by Ricci » Mon Nov 23, 2009 4:30 pm

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 )
...

User avatar
Roberto Lopez
HMG Founder
Posts: 3908
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 15 times
Been thanked: 140 times

Post by Roberto Lopez » Tue Nov 24, 2009 3:39 am

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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

Post Reply