TPrintPreview.PaintGraphicEx shows BMP as black blocks

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

TPrintPreview.PaintGraphicEx shows BMP as black blocks

Postby AndrewTBDev » 06/10/15 10:50

In recent changes to my sofware I am randomly getting black blocks instead of BMP graphics when using PaintGraphicEx on the TPrintPreview component.

I have been using TPrintPreview in the development of Delphi7-compiled business management software for a company for more than 10 years. (Best postcard I ever sent - thanks, Kambiz!) To-date I was using Preview v4.75 but after the problem occurred, I have tried v5.70 and v5.90 unsuccessfully. Suprisingly, attempts to re-create the previous revision of my software using saved source code did not get rid of the problem.

BMPs (e.g. the company logo), saved as resources in my .exe file, are copied to the TPrintPreview component using PrintGraphicEx. Most of the time this works. But after some program usage, it seems something goes wrong and images predominantly appear as black blocks. (I have checked that I am Free-ing all dynamically created objects, so as not to create memory leaks).

Errors have been seen on Windows XP, 7 and 8.1. Development/compilation has been tried under both Windows XP and Windows 7 - I'm considering porting the whole development to Windows 10 and Delphi XE10 Seattle in a hopeful attempt to kill the problem)

Any suggestions would be much appreciated.

Attached is a screenshot (with some privacy blurring) showing 4 pages of an invoice with some BMPs reproduced correctly and others showing black.

Thanks for the help!

Andrew
You do not have the required permissions to view the files attached to this post.
AndrewTBDev
Member
Member
 
Posts: 2
Joined: 03/09/13 10:09

Re: TPrintPreview.PaintGraphicEx shows BMP as black blocks

Postby Kambiz » 17/10/15 09:12

Hi Andrew,

Would you please answer these questions:

  • Do you destroy the bitmap after passing it to PaintGraphicEx?
  • What if you load the bitmap from a file instead of the resource?
  • Is the bitmap a device independent bitmap? Try to set PixelFormat property of the bitmap to either pf24bit or pf32bit.
  • Is the bitmap's Transparent property false?
And, please give me one of your bitmaps, so that I can regenerate the problem.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2394
Joined: 07/03/03 19:10

Re: TPrintPreview.PaintGraphicEx shows BMP as black blocks

Postby AndrewTBDev » 20/10/15 15:19

Hi Kambiz

Thanks for getting back to me on this - I'm still fighting it and getting frustrated!

This is the code that I am using to insert a BMP onto a TPrintPreview:

Code: Select all
  bmLogo := TBitMap.Create;
  try
    bmLogo.LoadFromResourceName(HInstance,'FULLLOGO');
    PrintBMP(2000,2000,5600,bmLogo);
  finally
    bmLogo.Free;
  end; // try




procedure PrintBMP(iX,iY : integer;
                   iWidth : integer;
                   bmPicture : TBitMap); overload;
var
  iBMPWidth : integer;
  iBMPHeight : integer;
begin
  iBMPWidth := ppOutput^.ConvertX(iWidth,mmHiMetric,ppOutput^.Units);
  iBMPHeight := ppOutput^.ConvertX((bmPicture.Height * iWidth) div  bmPicture.Width,mmHiMetric,ppOutput^.Units);
  ppOutput^.PaintGraphicEx(Rect(ppOutput^.ConvertX(iX,mmHiMetric,ppOutput^.Units),
                                ppOutput^.ConvertY(iY,mmHiMetric,ppOutput^.Units),
                                ppOutput^.ConvertX(iX,mmHiMetric,ppOutput^.Units) + iBMPWidth,
                                ppOutput^.ConvertY(iY,mmHiMetric,ppOutput^.Units) + iBMPHeight),
                           bmPicture,FALSE,FALSE,FALSE);
end; // PrintBMP



This code has been in use for years and has never gave any problems (with various versions of TPrintPreview).

Another BMP that I add to the printouts is a bar code which I create on-the-fly by simply painting on a TBitMap's Canvas. Again, I place it on the TPrintPreview component using the above PrintBMP routine. This BMP occasionally also comes out all black in the printouts.

In answer to your questions :
1) I always Free the TBitMap after use (see code above)
2) I am trying with loading from a file (but the fact that an on-the-fly created BMP also has problems, seems to imply that the resource is not necessarily the problem)
3) I do note that the BMP is 24bit and TBitMap.Create by default sets PixelFormat to pf8bit. I will try adjusting this setting.
4) TBitMap.Create by default sets Transparent to False. I have set the BMP itself, (using Paint Shop Pro) to have no transparency.

The users may use the software to generate invoices and other documents for hours without coming across a problem. Then, at other times, they might have a large number of black blocks, as shown in the original image I posted. I have only encountered it once on my development PC.

An issue that I created in July does not have the problem. An attempt to recompile that exe, on the same PC, using all the same components, library units and archived source code creates a slightly different sized exe file, and this does show the problems. I have also compiled the code on a different PC, which produced an exe file that was again different in size to the other two, and this also produced black blocks.

I've attached the company logo BMP that I am putting at the top of all documents.

Thank for your help!

Andrew
You do not have the required permissions to view the files attached to this post.
AndrewTBDev
Member
Member
 
Posts: 2
Joined: 03/09/13 10:09

Re: TPrintPreview.PaintGraphicEx shows BMP as black blocks

Postby Kambiz » 31/10/15 11:08

Hi Andrew,

I created more than 10,000 pages using you sample image. Also, I left the code running for several hours. In both cases, no problem occurred.

What about to load the image only once and use the cached copy for printing? In that case, it is better after loading the image from resource, call TBitmap.Dormant method to release the GDI resource.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2394
Joined: 07/03/03 19:10


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest