Multi page TIFF file to jpg conversion? (SOLVED)

Multi page TIFF file to jpg conversion? (SOLVED)

Postby Horizon » Sun Aug 08, 2021 9:23 am

Hi,

I use GDIPlusConvertImage( cImageIni, cImageEnd ) function to convert but It only converts first page to jpg file. Is there any workaround?

Thanks.
Last edited by Horizon on Tue Aug 10, 2021 8:54 am, edited 1 time in total.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Multi page TIFF file to jpg conversion?

Postby Antonio Linares » Mon Aug 09, 2021 9:56 am

Thanks to Manuel Alvarez as usual :-)

Code: Select all  Expand view  RUN
FUNCTION frametif()

  LOCAL i
  LOCAL oBmp := GDIBmp():New( )
  LOCAL hbmp := GDIPLOADDIRECTIMAGE("yo.tif" )

  LOCAL nFrames = GDIPLUSIMGGETFRAMECOUNT( hbmp )

   Msginfo( nFrames )

   FOR i = 1 TO nFrames
      obmp:hbmp = GDIPLUSIMGGETFRAME( hbmp, i )
      obmp:save( "tu"+AllTrim(Str(i))+".jpg")
      oBmp:END()
   NEXT

   obmp:hbmp = hbmp
   obmp:END()

RETURN nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Multi page TIFF file to jpg conversion?

Postby Horizon » Mon Aug 09, 2021 12:35 pm

Hi Antonio,

Code: Select all  Expand view  RUN
ICRA_Fnc.obj : error LNK2001: çözümlenmemiş dış sembol _HB_FUN_GDIPLOADDIRECTIMAGE
ICRA_Fnc.obj : error LNK2001: çözümlenmemiş dış sembol _HB_FUN_GDIPLUSIMGGETFRAMECOUNT
ICRA_Fnc.obj : error LNK2001: çözümlenmemiş dış sembol _HB_FUN_GDIPLUSIMGGETFRAME


Where can i found this function?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Multi page TIFF file to jpg conversion?

Postby mastintin » Mon Aug 09, 2021 2:13 pm

Code: Select all  Expand view  RUN

HB_FUNC ( GDIPLOADDIRECTIMAGE )
{
   LPWSTR file     = AnsiToWide( ( char * ) hb_parc( 1 ) );
   Bitmap * original =  new Bitmap(file  );
   hb_retptr( original );
}
 

Code: Select all  Expand view  RUN


HB_FUNC( GDIPLUSIMGGETFRAMECOUNT )
{
  Bitmap * original = ( Bitmap * ) hb_parptr( 1 );

  UINT nFrame = original->GetFrameDimensionsCount();
  GUID* pDimensionIDs = ( GUID* )malloc( sizeof(GUID)*nFrame );

  original->GetFrameDimensionsList(pDimensionIDs, nFrame);
  UINT frameCount = original->GetFrameCount(pDimensionIDs );
  free( pDimensionIDs );
  hb_retni( frameCount );
}
 


Code: Select all  Expand view  RUN

HB_FUNC( GDIPLUSIMGGETFRAME )
{
  Bitmap * gifImage = ( Bitmap * ) hb_parptr( 1 );
  int index = hb_parni(2) ;

  UINT nFrame = gifImage->GetFrameDimensionsCount();

  GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*nFrame);

  gifImage->GetFrameDimensionsList( pDimensionIDs, nFrame);

  gifImage->SelectActiveFrame( pDimensionIDs , index );

  int nWidth  =  gifImage->GetWidth() ;
  int nHeight =  gifImage->GetHeight() ;

  Bitmap * frameImage = new Bitmap( nWidth, nHeight  );
  Graphics * gr = new Graphics( frameImage );

  gr->DrawImage(gifImage, 0, 0, nWidth, nHeight);

  free( pDimensionIDs ) ;
  delete gr ;

  hb_retptr( frameImage );
}

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Multi page TIFF file to jpg conversion?

Postby Horizon » Mon Aug 09, 2021 7:32 pm

Thank you. I could not compile this lines.

Code: Select all  Expand view  RUN
4284    **----------------------------------------------------------------------
4285    #pragma BEGINDUMP
4286    #define _WIN32_WINNT 0x0500
4287    #define WINVER 0x0500
4288    #include "windows.h"
4289    #include "hbapi.h"
4290    HB_FUNC( GETINPUTSTATE )
4291    {
4292        LASTINPUTINFO lpi;
4293        lpi.cbSize = sizeof(LASTINPUTINFO);
4294        if (!GetLastInputInfo(&lpi))
4295        {
4296        hb_retni(0);
4297        }
4298        hb_retni(lpi.dwTime);
4299    }
4300
4301    HB_FUNC ( GDIPLOADDIRECTIMAGE )
4302    {
4303       LPWSTR file     = AnsiToWide( ( char * ) hb_parc( 1 ) );
4304       Bitmap * original =  new Bitmap(file  );
4305       hb_retptr( original );
4306    }
4307
4308    HB_FUNC( GDIPLUSIMGGETFRAMECOUNT )
4309    {
4310      Bitmap * original = ( Bitmap * ) hb_parptr( 1 );
4311
4312      UINT nFrame = original->GetFrameDimensionsCount();
4313      GUID* pDimensionIDs = ( GUID* )malloc( sizeof(GUID)*nFrame );
4314
4315      original->GetFrameDimensionsList(pDimensionIDs, nFrame);
4316      UINT frameCount = original->GetFrameCount(pDimensionIDs );
4317      free( pDimensionIDs );
4318      hb_retni( frameCount );
4319    }
4320
4321    HB_FUNC( GDIPLUSIMGGETFRAME )
4322    {
4323      Bitmap * gifImage = ( Bitmap * ) hb_parptr( 1 );
4324      int index = hb_parni(2) ;
4325
4326      UINT nFrame = gifImage->GetFrameDimensionsCount();
4327
4328      GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*nFrame);
4329
4330      gifImage->GetFrameDimensionsList( pDimensionIDs, nFrame);
4331
4332      gifImage->SelectActiveFrame( pDimensionIDs , index );
4333
4334      int nWidth  =  gifImage->GetWidth() ;
4335      int nHeight =  gifImage->GetHeight() ;
4336
4337      Bitmap * frameImage = new Bitmap( nWidth, nHeight  );
4338      Graphics * gr = new Graphics( frameImage );
4339
4340      gr->DrawImage(gifImage, 0, 0, nWidth, nHeight);
4341
4342      free( pDimensionIDs ) ;
4343      delete gr ;
4344
4345      hb_retptr( frameImage );
4346    }
4347    #pragma ENDDUMP


Code: Select all  Expand view  RUN
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30040 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

TApplication.c
.\TApplication.prg(4303): error C3861: 'AnsiToWide': identifier not found
.\TApplication.prg(4304): error C2065: 'Bitmap': undeclared identifier
.\TApplication.prg(4304): error C2065: 'original': undeclared identifier
.\TApplication.prg(4304): error C2061: syntax error: identifier 'Bitmap'
.\TApplication.prg(4305): error C2065: 'original': undeclared identifier
.\TApplication.prg(4310): error C2065: 'Bitmap': undeclared identifier
.\TApplication.prg(4310): error C2065: 'original': undeclared identifier
.\TApplication.prg(4310): error C2065: 'Bitmap': undeclared identifier
.\TApplication.prg(4310): error C2059: syntax error: ')'
.\TApplication.prg(4312): error C2065: 'original': undeclared identifier
.\TApplication.prg(4315): error C2065: 'original': undeclared identifier
.\TApplication.prg(4316): error C2065: 'original': undeclared identifier
.\TApplication.prg(4323): error C2065: 'Bitmap': undeclared identifier
.\TApplication.prg(4323): error C2065: 'gifImage': undeclared identifier
.\TApplication.prg(4323): error C2065: 'Bitmap': undeclared identifier
.\TApplication.prg(4323): error C2059: syntax error: ')'
.\TApplication.prg(4326): error C2065: 'gifImage': undeclared identifier
.\TApplication.prg(4330): error C2065: 'gifImage': undeclared identifier
.\TApplication.prg(4332): error C2065: 'gifImage': undeclared identifier
.\TApplication.prg(4334): error C2065: 'gifImage': undeclared identifier
.\TApplication.prg(4335): error C2065: 'gifImage': undeclared identifier
.\TApplication.prg(4337): error C2065: 'Bitmap': undeclared identifier
.\TApplication.prg(4337): error C2065: 'frameImage': undeclared identifier
.\TApplication.prg(4337): error C2061: syntax error: identifier 'Bitmap'
.\TApplication.prg(4338): error C2065: 'Graphics': undeclared identifier
.\TApplication.prg(4338): error C2065: 'gr': undeclared identifier
.\TApplication.prg(4338): error C2061: syntax error: identifier 'Graphics'
.\TApplication.prg(4340): error C2065: 'gr': undeclared identifier
.\TApplication.prg(4340): error C2065: 'gifImage': undeclared identifier
.\TApplication.prg(4343): error C2065: 'gr': undeclared identifier
.\TApplication.prg(4343): error C2541: 'delete': cannot delete objects that are
not pointers
.\TApplication.prg(4345): error C2065: 'frameImage': undeclared identifier
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio\2019
\Community\VC\Tools\MSVC\14.29.30037\bin\HostX86\x86\cl.exe"'
: return code '0x2
'

Stop.


Any help. Thanks
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Multi page TIFF file to jpg conversion?

Postby mastintin » Mon Aug 09, 2021 8:26 pm

in fwh distribution ...

c:\fwh\source\winapi\gdiplus.cpp file, copy this file in your directory files code and add this lines , add this file in your makefile and compile ...
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Multi page TIFF file to jpg conversion?

Postby Horizon » Tue Aug 10, 2021 8:53 am

mastintin wrote:in fwh distribution ...

c:\fwh\source\winapi\gdiplus.cpp file, copy this file in your directory files code and add this lines , add this file in your makefile and compile ...


Thank you very much. I have solved my problem via add my makefile like you said.

Antonio, Can you please add this extensions to gdiplus.cpp.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Multi page TIFF file to jpg conversion? (SOLVED)

Postby Antonio Linares » Tue Aug 10, 2021 10:45 am

Hakan,

Please check your email

We have renamed function FrameTiff( cTiffFileName ) and also GDIPLUSLOADDIRECTIMAGE()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Multi page TIFF file to jpg conversion? (SOLVED)

Postby Horizon » Tue Aug 10, 2021 7:42 pm

Hi Antonio,

There is an error with new libs.
Code: Select all  Expand view  RUN
FiveH32.lib(TGDIPLUS.obj) : error LNK2001: unresolved external symbol _HB_FUN_CFILENAMENOEXT
IcraW.exe : fatal error LNK1120: 1 unresolved externals


I think it is misspelling (cFileNoExt)

Workaround
Code: Select all  Expand view  RUN
FUNCTION cFileNameNoExt(cText)
RETURN cFileNoExt(cText)
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Multi page TIFF file to jpg conversion? (SOLVED)

Postby Antonio Linares » Tue Aug 10, 2021 10:30 pm

Hakan,

many thanks for your feedback

Is it working as expected ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Multi page TIFF file to jpg conversion? (SOLVED)

Postby Horizon » Wed Aug 11, 2021 6:46 am

Antonio Linares wrote:Hakan,

many thanks for your feedback

Is it working as expected ?


Hi Antonio,

I made some minor changes your function like that.
Code: Select all  Expand view  RUN
FUNCTION TIFFtoJPG(cFileTIF, cFileJPG)

  LOCAL i, aResult := {}, clocal
  LOCAL oBmp := GDIBmp():New( )
  LOCAL hbmp := GDIPLUSLOADDIRECTIMAGE(cFileTIF)
  LOCAL nFrames := GDIPLUSIMGGETFRAMECOUNT( hbmp )

//  Msginfo( nFrames )

    FOR i = 1 TO nFrames
      obmp:hbmp = GDIPLUSIMGGETFRAME( hbmp, i )
     
      clocal := cFilePath(cFileJPG)+cFileNoExt(cFileJPG)+"_"+AllTrim(Str(i))+".jpg"
      obmp:save( clocal )
      oBmp:END()
      AAdd(aResult, {cFileTIF, clocal})
     
    NEXT

    obmp:hbmp = hbmp
    obmp:END()

RETURN aResult
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Multi page TIFF file to jpg conversion? (SOLVED)

Postby Antonio Linares » Fri Aug 13, 2021 12:24 pm

thank you

already implemented your version in next FWH build
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 104 guests