TImage Class

Post Reply
byron.hopp
Posts: 390
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Been thanked: 1 time
Contact:

TImage Class

Post 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,
Thanks,
Byron Hopp
Matrix Computer Services
User avatar
karinha
Posts: 7963
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 5 times
Contact:

Re: TImage Class

Post 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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
Posts: 7963
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 5 times
Contact:

Re: TImage Class

Post 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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
cnavarro
Posts: 6572
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 4 times
Been thanked: 6 times

Re: TImage Class

Post 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.
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
User avatar
cnavarro
Posts: 6572
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 4 times
Been thanked: 6 times

Re: TImage Class

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

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

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
Post Reply