Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Bitmap prints a black box randomly


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Sep 28, 2017 4:48 PM Last Post By: Enrico Pergola Threads: [ Previous | Next ]
Enrico Pergola

Posts: 32
Registered: 7/15/04
Bitmap prints a black box randomly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 18, 2017 4:19 PM
Hi. I have a program that prints a small logo on a Receipt printer.
Randomly (every 30 printouts or so) it prints a black box.
I load a Tbitmap object form a bmp file once, then print the image to the printer canvas.
This is the code that does the printing (I do not recall where I downloaded it from).
procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: Graphics.TBitmap);
var
Header, Bits: Pointer;
HeaderSize: DWORD;
BitsSize: DWORD;
begin
GetDIBSizes(ABitmap.Handle, HeaderSize, BitsSize);
Header := AllocMem(HeaderSize);
Bits := AllocMem(BitsSize);
try
GetDIB(ABitmap.Handle, ABitmap.Palette, Header^, Bits^);
StretchDIBits(Canvas.Handle, DestRect.Left, DestRect.Top,
DestRect.Right, DestRect.Bottom,
0, 0, ABitmap.Width, ABitmap.Height, Bits, TBitmapInfo(Header^),
DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(Header, HeaderSize);
FreeMem(Bits, BitsSize);
end;
end;

The customer has another (all-in-one) printer attached to the PC that they use to make photocopies.
Could that have anything to do with this problem?
Any other suggestion?

--
E.P.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Bitmap prints a black box randomly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 18, 2017 4:32 PM   in response to: Enrico Pergola in response to: Enrico Pergola
Enrico Pergola wrote:

I load a Tbitmap object form a bmp file once, then print the image to
the printer canvas. This is the code that does the printing (I do
not recall where I downloaded it from).

Why not simply call TCanvas.StretchDraw() instead?

procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap:
Graphics.TBitmap);
begin
  Canvas.StretchDraw(DestRect, ABitmap);
end;


This simply calls ABitmap.Draw(Canvas, DestRect), letting ABitmap
decide how it wants to draw itself onto the Canvas.

--
Remy Lebeau (TeamB)
Enrico Pergola

Posts: 32
Registered: 7/15/04
Re: Bitmap prints a black box randomly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 18, 2017 4:44 PM   in response to: Enrico Pergola in response to: Enrico Pergola
Thanks Remy.
Tomorrow I'll try that. Do you think this method is "safer" than what I am presently using and probably will eliminate the black box problem?
Alex Belo

Posts: 626
Registered: 10/8/06
Re: Bitmap prints a black box randomly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2017 3:09 AM   in response to: Enrico Pergola in response to: Enrico Pergola
Enrico Pergola wrote:

Randomly ... it prints a black box.

Such problem is typical manifestation of problems with multithreading.

Is multithreading somehow involved in your case?

--
Alex
Enrico Pergola

Posts: 32
Registered: 7/15/04
Re: Bitmap prints a black box randomly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2017 4:48 PM   in response to: Enrico Pergola in response to: Enrico Pergola
No. No multithreading. It does not happen with me. Only with my client. I guess there si something that
the OS leaves in the systema when they make a photocopy on the other printer (epson, i think).
I remember once I had a problem with the orientation. They had a receipt printer and an Epson printer to print reports.
They used to set the orientation of the Epson to landscape and that kept the orientation set to landscape on the receipt printer too. That was easy to fxs, just set the orientation to portrait in my app echa time before printing. Here i have no idea what may leave in memory that photocopy.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02