FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TImage Class
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
TImage Class
Posted: Tue Mar 11, 2025 07:21 PM

I have been using the TImage class because my scanner hardware died, and the other scanner only produces JPG instead of BMP. However I cannot get the Method RotateImage to work it says message not found, and I cannot seem to resize the image, does this work, or am I doing something wrong.

Thanks,

Thanks,

Byron Hopp

Matrix Computer Services
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: TImage Class
Posted: Wed Mar 12, 2025 03:18 PM
Are you doing something like that?

https://forums.fivetechsupport.com/viewtopic.php?p=152737#p152737

https://forums.fivetechsupport.com/viewtopic.php?f=3&t=23500&p=126264&hilit=ResizeBmp#p126264

Post the code of how you are doing it, it makes it easier to help.

Gracias, tks.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: TImage Class
Posted: Wed Mar 12, 2025 03:25 PM
Maybe,
**==========================================================================
STATIC FUNCTION GetPngMC(oImage)
**==========================================================================
LOCAL cFile,cStrBmp

cFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" + ;
                    "DIB   (*.dib)| *.dib|" + ;
                    "PCX   (*.pcx)| *.pcx|" + ;
                    "JPEG  (*.jpg)| *.jpg|" + ;
                    "GIF   (*.gif)| *.gif|" + ;
                    "TARGA (*.tga)| *.tga|" + ;
                    "RLE   (*.rle)| *.rle|" + ;
                    "All Files (*.*)| *.*"    ;
                    ,"Selecione o arquivo", 4 )

IF !Empty(cFile) .and. File(cFile)
   oImage:LoadBmp( cFile )
   
   //redimenciona o tamanho da foto 256 x 194 pixel
   oImage:hBitmap := ResizeBmp( oImage:hBitmap, 256, 194, .T. ) //redimensiona
   
   cStrBmp := BmpToStr(oImage:hBitmap)      //transf de img para string
   oImage:Refresh()

	//   0 -> Bmp  //   2 -> Jpg   //  13 -> Png
   oImage:SaveImage(cNome, 13, 75)
ENDIF

RETURN NIL
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: TImage Class
Posted: Wed Mar 12, 2025 06:52 PM
byron.hopp wrote: I have been using the TImage class because my scanner hardware died, and the other scanner only produces JPG instead of BMP. However I cannot get the Method RotateImage to work it says message not found, and I cannot seem to resize the image, does this work, or am I doing something wrong.

Thanks,
There are some FreeImage DLLS in which the Rotate function does not appear and the RotateClassic function exists, so to maintain compatibility with previous versions we are going to make the following changes to the class
//----------------------------------------------------------------------------//

METHOD RotateImage( nAngle ) CLASS TImage

   local hDib := DibFromBitmap( ::hBitmap )
   local cTempFile := cTempFile( , "BMP" )
   local lSaved, hBmp
   local hOldBmp  := ::hBitmap
   local hOldPal  := ::hPalette

   DibWrite( cTempFile, hDib )

   GloBalFree( hDib )

   hBmp = FIROTATEIMG( cTempFile, nAngle, Self )   // New Last parameter
   
   FErase( cTempFile )
.../...

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

Function FIROTATEIMG( cSrcFile, nAngle, oImg )   // Look new last parameter

   local nSrcFormat, hDib, hDib2, lOk
   local nFormat, hInfoH, hInfo, hBits, hWnd, hDC, hBmp := 0

   nSrcFormat := FIGETFILETYPE( cSrcFile, 0 )

   hDib := FILOAD( nSrcFormat, cSrcFile, 0 )

   IF hDib <> 0
      hDib2 := FIRotate( hDib, nAngle )
      // New
      if !hb_IsNumeric( hDib2 ) .or. hDib2 == 0
         hDib2 := FIRotateClassic( hDib, nAngle )
      endif
      IF hb_IsNumeric( hDib2 ) .and. hDib2 <> 0
         hInfoH  := FIGETINFOHEADER( hDib2 )
         hInfo   := FIGETINFO( hDib2 )
         hBits   := FIGETBITS( hDib2 )
         hWnd    := oImg:oWnd:hWnd  // GETDESKTOPWINDOW()
.../...

 //----------------------------------------------------------------------------//
 
 DLL32 FUNCTION FIRotate( hDib AS LONG, nAngle AS _DOUBLE, nColor AS LONG ) AS LONG ;
      PASCAL FROM If( IsExe64(), "FreeImage_Rotate", "_FreeImage_Rotate@16" ) ;
      LIB hLib

// New Function
DLL32 FUNCTION FIRotateClassic( hDib AS LONG, nAngle AS _DOUBLE ) AS LONG ;
      PASCAL FROM If( IsExe64(), "FreeImage_RotateClassic", "_FreeImage_RotateClassic@12" ) ;
      LIB hLib
I hope it works properly for you now.
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: TImage Class
Posted: Wed Mar 12, 2025 09:42 PM
Sample of use
#include "FiveWin.ch"

static oDlg, oBtn1, oBtn2, oImg1, oImg2, oImg, lTodo := .F.

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

function Main( cImgName1, cPath )

   DEFAULT cImgName1 := "d:\fwh\fwhteam\samples\splash.jpg"

   if Empty( cPath )

      DEFINE DIALOG oDlg SIZE 414, 702 // 844
      
      @ 30, 1 IMAGE oImg1 FILENAME cImgName1 SIZE 207, 300 OF oDlg PIXEL //ADJUST SCROLL
      
      ACTIVATE DIALOG oDlg ;
         ON INIT ( oDlg:SetPos( 0, ScreenWidth() - oDlg:nWidth + 2 ),  BuildButtonBar() )
   endif

return nil

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

function BuildButtonBar()

   local oBar, hTemp, uTemp

   DEFINE BUTTONBAR oBar SIZE 60, 60 OF oDlg //2007

   DEFINE BUTTON OF oBar RESOURCE "Replace" TOOLTIP "Rotar" ;
      PROMPT "Rotate" ACTION ( oImg1:hBitMap := oImg1:RotateImage( 90.00 ), oImg1:Refresh() )
      
   DEFINE BUTTON OF oBar RESOURCE "print" TOOLTIP "Imprimir" ;
      PROMPT "Imprimir" ACTION ( ImgPrint( @oImg1, @oImg2, @oDlg ) )

   DEFINE BUTTON OF oBar RESOURCE "exit" TOOLTIP "Salir" ;
      PROMPT "Salir" ACTION oDlg:End()

return nil

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

STATIC FUNCTION ImgPrint( oImg1, oImg2, oDlg )
   
   local oPrn
   
   PRINT oPrn PREVIEW
   PAGE

   @ 0, 0 PRINT TO oPrn IMAGE oImg1:cBmpFile SIZE 8.5, 11 INCHES NOTRANSPARENT //STRETCH

   ENDPAGE
   ENDPRINT
   
RETURN ( .T. )

//----------------------------------------------------------------------------//
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces

Continue the discussion