Page 1 of 1

TImage Class

Posted: Tue Mar 11, 2025 7:21 pm
by byron.hopp
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,

Re: TImage Class

Posted: Wed Mar 12, 2025 3:18 pm
by karinha
Are you doing something like that?

viewtopic.php?p=152737#p152737

viewtopic.php?f=3&t=23500&p=126264&hili ... mp#p126264

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

Gracias, tks.

Regards, saludos.

Re: TImage Class

Posted: Wed Mar 12, 2025 3:25 pm
by karinha
Maybe,

Code: Select all | Expand

**==========================================================================
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.

Re: TImage Class

Posted: Wed Mar 12, 2025 6:52 pm
by cnavarro
byron.hopp wrote: Tue Mar 11, 2025 7: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,
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

Code: Select all | Expand


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

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.

Re: TImage Class

Posted: Wed Mar 12, 2025 9:42 pm
by cnavarro
Sample of use

Code: Select all | Expand

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

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