Page 1 of 1

Printing JPGs using TPrinter

Posted: Thu Dec 27, 2007 4:12 am
by James Bott
I am trying to print a JPG on a report using TPrinter. I get nothing displayed in the preview. Bitmaps work.

I also found that you MUST use REDEFINE to get an oImage object.

Below is my code. Any suggestions?

James

Code: Select all

// Test Printing JPB image

#include "FiveWin.ch"
#include "image.ch"


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

function Main()
   local oPrn, oImage, cFile:="fivewin.jpg"

   //oImage:= TImage():new(1,1,150,150,,cFile ) // oImage is nil

   //@ 0,0 image oImage file cFile  // oImage is nil

   //@ 0, 0 IMAGE oImage SIZE 150, 150 OF oPrn // oImage is nil

   oImage:= TImage():redefine(,cFile,oPrn) // oImage is object

   //msgInfo( valtype( oImage ) )

   PRINT oPrn PREVIEW
      oImage:oWnd:= oPrn
      PAGE

         //oPrn:sayBitmap( 200, 200, cFile) // works with bitmap

         oPrn:SayImage( 20, 20, oImage )  // nothing shows

         oPrn:say(500,200, "Text goes here.")

      ENDPAGE
   ENDPRINT

   oImage:end()

return nil

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

Re: Printing JPGs using TPrinter

Posted: Thu Dec 27, 2007 5:18 am
by Richard Chidiak
James

This way works

oIMAGE := TIMAGE():Define(,DIMAGE)
OPRN:SAYIMAGE(LineIMP,ColIMP,OIMAGE,LARGE,Height)
OIMAGE:END()

Hth

Richard

Posted: Thu Dec 27, 2007 5:38 am
by James Bott
Richard,

Thanks for the response--now it is working! Here is my revised code.

James

Code: Select all

#include "FiveWin.ch"
#include "image.ch"


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

function Main()
   local oPrn, oImage, cFile:="fivewin.jpg"

   oImage:=TImage():define(,cFile)

   PRINT oPrn PREVIEW
    
      PAGE

         oPrn:SayImage( 20, 20, oImage, 100, 100 ) 

         oPrn:say(500,200, "Text goes here.")

      ENDPAGE
   ENDPRINT

   oImage:end()

return nil

Posted: Thu Dec 27, 2007 4:25 pm
by nageswaragunupudi
Can we, instead of reading from a disk file, assign the buffer read from a memo field ?

Posted: Thu Dec 27, 2007 6:10 pm
by Antonio Linares
Nageswararao,

You may read it from the memo, then create a temporary file and load it from there. Finally erase the temp file.

Posted: Fri Dec 28, 2007 3:01 am
by nageswaragunupudi
Mr Antonio

I confess I am not good at FreeImage API. But I see these functions and write up in documentation.
Memory I/O streams
Memory I/O routines use a specialized version of the FreeImageIO structure, targeted to save/load FIBITMAP images to/from a memory stream. Just like you would do with a file stream. Memory file streams support loading and saving of FIBITMAP in a memory file (managed internally by FreeImage). They also support seeking and telling in the memory file.
Examples of using these functions would be to store image files as blobs in a database, or to write image files to a Internet stream.
............
..........
FreeImage_LoadFromMemory
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags FI_DEFAULT(0));
This function does for memory streams what FreeImage_Load does for file streams.
..........
I think it should be possible to extend the TImage class to read from memory.