Re:Printing Graphics?
Quote
smcarea...@sundog.thegap.com (Stephen McAreavey) wrote:
>I have been trying to print bitmaps from my delphi app but I just get
>a blank page every time. My code is correct, even the supplied demo
>apps (Graphex) will not print properly. I had heard that it could be a
>memory problem, but I have plenty of RAM and disk space, so I don't
>think that this is the source of my problem. I have got a GDI printer
>though - could this be the reason? Using the TForm.Print method works
>fine though.
I had a similar problem - I was using an HP Laserjet 4l. I found that
with some printers it works, some it doesn't. My workaround is to
copy it to a TDib object, then print that. It works on all of the
printers I have tested!
Here's my code - I'm sure it can be modified to your purposes. prn is
the printer.canvas handle, prect is the destination rectangle, and bmp
is the bitmap. I keifed the idea from the VCL source.
Procedure DIBPrint(prn: hDC; pRect: TRect; bmp: TBitmap);
var bmpInfo: pBITMAPINFO;
InfoSize: Integer;
ImageSize: LongInt;
Image: Pointer;
DIBwidth, DIBheight, printwidth, printheight: integer;
begin
GetDibSizes(bmp.Handle, InfoSize, ImageSize);
bmpInfo := MemAlloc(InfoSize);
Image := MemAlloc(ImageSize);
try
GetDib(bmp.Handle, 0, bmpInfo^, Image^);
with bmpInfo^.bmiHeader do
begin
DIBWidth := biWidth;
DIBHeight := biHeight;
end;
PrintWidth := pRect.Right - pRect.Left;
PrintHeight := pRect.Bottom - pRect.Top;
StretchDIBits(prn, pRect.Left, pRect.Top, PrintWidth,
PrintHeight, 0, 0,
DIBWidth, DIBHeight, Image, bmpInfo^,
DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(image, imageSize);
FreeMem(bmpInfo, InfoSize);
end;
end;
Good luck!
Jenica Fuller
jen...@xmission.com