ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 RenderToCanvas returns with empty screens
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Reiner

3 Posts

Posted - Sep 26 2018 :  16:09:03  Show Profile  Reply
Hi,
we have just put the TIEBitmap and TImageEnIO into the kernel of our printing application to handle multipage tiff sources. In principle everything works as expected ... but randomly a few pages come out as blanc pages.

We could locate the issue as a possible timing problem while using the RenderToCanvas() method. Here the results, focussing on the central methods:

Sequence (1) - Straight forward
ietifbmp->RenderToCanvas(PrnBmp->Canvas,L,T,W,H,rfLanczos3,0,clWhite);
Printer()->Canvas->StretchDraw(Printer()->Canvas->ClipRect,PrnBmp);
===> blanc pages are printed randomly (about one of 10)

Sequence (2)- Inserting a delay
ietifbmp->RenderToCanvas(PrnBmp->Canvas,L,T,W,H,rfLanczos3,0,clWhite);
DelayLoop(500 ms) // containing Application->ProcessMessages()
Printer()->Canvas->StretchDraw(Printer()->Canvas->ClipRect, PrnBmp);
===> all pages are printed, anytime

My assumption: The RenderToCanvas() method seems to work asynchronly, i.e. it returns before the target bitmap is completed.

Is there any solution like an event or a state value that can inform us about the rendering process state.

Thank you!
Reiner

xequte

38194 Posts

Posted - Sep 27 2018 :  15:24:02  Show Profile  Reply
Hi Reiner

RenderToCanvas isn't asynchronous, but is it possible that Printer->Canvas work asynchronously (using Windows messages, which explains the ProcessMessages() calls).

Is PrnBmp a TIEBitmap or TBitmap?

Unfortunately we cannot reproduce the error here. Are you able to create a simple test application that shows the issue?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Reiner

3 Posts

Posted - Sep 28 2018 :  01:57:02  Show Profile  Reply
Hi Nigel,

Thanks a lot for your prompt reply.
This is already a valuable information.
I will prepare a little test program for further research and come back to this thread as soon as possible.

Reiner
Go to Top of Page

Reiner

3 Posts

Posted - Sep 29 2018 :  14:41:43  Show Profile  Reply
Hi again Nigel,

it took me a while, because our test program did not show any problems with the multipage-tiff-printing.


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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)

#pragma link "hyiedefs"
#pragma link "hyieutils"
#pragma link "iesettings"
#pragma link "iexLayers"
#pragma link "iexRulers"
#pragma link "ieopensavedlg"
#pragma link "iexBitmaps"
#pragma link "ieview"
#pragma link "imageenio"
#pragma link "imageenview"
#pragma resource "*.dfm"

TForm1 *Form1;
TPrinter *PRN;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
//---------------------------------------------------------------------------
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button0Click(TObject *Sender)
//---------------------------------------------------------------------------
{
   TIETIFFHandler *tiffs=new TIETIFFHandler();
   TMemoryStream  *tmp  =new TMemoryStream();
   TIEBitmap      *iebmp=new TIEBitmap();
   TImageEnIO     *IO   =new TImageEnIO(iebmp);
   TBitmap        *bmp  =new TBitmap;

   bmp->Width  = 2479;
   bmp->Height = 3508;

   PRN=Printer();

   OpenFileDlg->Execute();

   if(OpenFileDlg->FileNameW!="")
   {
	 PRN->BeginDoc();
	 PRN->Canvas->CopyMode=cmSrcCopy;

	 tiffs->ReadFile(OpenFileDlg->FileNameW);
	 int pages=tiffs->GetPagesCount();

	 Button0->Caption=IntToStr(pages)+" Pages";

	 for(int i=0; i<pages; i++) // print all pages of the tif-file
	 {
	   tmp->Position=0; tiffs->WriteStream(tmp,i);
	   tmp->Position=0; IO->LoadFromStreamTIFF(tmp);

	   // render to intermediate bitmap (this step is not really necessary)
	    iebmp->RenderToCanvas(bmp->Canvas,0,0,2479,3508,rfFastLinear,0,clWhite);

	   PRN->Canvas->StretchDraw(PRN->Canvas->ClipRect,bmp);
	   if(i<pages-1)PRN->NewPage();

	   //  IM->Picture->Bitmap->Assign(bmp); // TImage control on Form1
	   Button0->Caption=IntToStr(pages)+" Pages printed";
	 }

	 PRN->EndDoc();
   }

   delete bmp;
   delete IO;
   delete iebmp;
   delete tmp;
   delete tiffs;
}
//---------------------------------------------------------------------------



In my final application the rendering and printing portion shown above is located within a Windows service class. Probably here we are facing the asynchronous effects providing us blanc pages. Here your assumption regarding the Printer->Canvas behavior hits the mark.

After a few more hours of try&error I now have noticed, that if we just add the following 1-dot-Draw function ahead the main StretchDraw(), the blanc pages disappear:

PRN->Canvas->Draw(0,0,1_dot_bmp); // added line
PRN->Canvas->StretchDraw(PRN->Canvas->ClipRect,bmp);

I admit that this does not get us to the root cause but it gets our application working stable up to now.

Thank you again
Reiner
Go to Top of Page

xequte

38194 Posts

Posted - Sep 29 2018 :  22:43:03  Show Profile  Reply
Hi Reiner

Good to hear you have found a working solution.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: