Article View: comp.lang.pascal.delphi.misc
Article #542Printing bitmap: Nothing is printed. WHY?
From: Thomas Nagy
Date: Tue, 09 Nov 1999 00:00
Date: Tue, 09 Nov 1999 00:00
79 lines
3121 bytes
3121 bytes
I went through many of the printing related messages on Dejanews and
other websites and followed the instructions re: bitmap printing. However,
all I get is an empty page when I try to print in the procedure below.
(I am using D1 and testing printing on HP Laserjet IIIP if it's important.)
What am I doing wrong? The bitmap looks perfect in the saved file.
procedure TForm1.PrintButtonClick(Sender: TObject);
var
FormImage : TBitmap;
Orientation : TPrinterOrientation;
ph, pw : integer;
fx, fy : double;
w, h : integer;
procedure PrintBitmap(Bitmap: TBitmap; L,T,W,H: Integer);
var
BitmapHeader: pBitmapInfo;
BitmapImage : Pointer;
HeaderSize : Integer;
ImageSize : LongInt;
begin
GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
GetMem(BitmapHeader, HeaderSize);
GetMem(BitmapImage, ImageSize);
try
GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
StretchDIBits(Printer.Canvas.Handle, L, T, W, H,
0, 0, Bitmap.Width, Bitmap.Height, BitmapImage,
TBitmapInfo(BitmapHeader^), DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(BitmapHeader, HeaderSize);
FreeMem(BitmapImage, ImageSize);
end;
end;
begin
Application.ProcessMessages;
Orientation := Printer.Orientation;
Printer.Orientation := poLandscape;
try
{FormImage := GetFormImage; this is no good, things are missing}
FormImage := TBitmap.Create;
FormImage.Height := ClientHeight;
FormImage.Width := ClientWidth;
FormImage.Canvas.CopyRect(ClientRect, Canvas, ClientRect);
FormImage.SaveToFile('form.bmp');
ph := Printer.PageHeight;
pw := Printer.PageWidth;
Printer.BeginDoc;
w := ClientWidth;
h := ClientHeight;
if pw < ph then
begin
fx := pw;
fy := h*(pw/w);
end
else
begin
fx := w*(ph/h);
fy := ph;
end;
PrintBitmap(FormImage, 0, 0, Round(fx), Round(fy));
Printer.EndDoc;
finally
Printer.Orientation := Orientation;
FormImage.Free;
end;
end;
Thomas Nagy
-----------------------------------------------------------------
Check out my cats! (http://members.home.net/2832779232/index.htm)
Free Office Suite: http://www.stardivision.com/so40/index.html
Technical Details
Message-ID:
<LLRV3.9418$Q5.387331@news1.rdc1.ab.home.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1091e5,af8e8541d2744038,start X-Google-Attributes: gid1091e5,public X-Google-Thread: 10baee,af8e8541d2744038,start X-Google-Attributes: gid10baee,public From: thomas.nagy@home.com (Thomas Nagy) Subject: Printing bitmap: Nothing is printed. WHY? Date: 1999/11/09 Message-ID: <LLRV3.9418$Q5.387331@news1.rdc1.ab.home.com> X-Deja-AN: 546370707 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.ab.home.com 942139499 24.66.122.157 (Tue, 09 Nov 1999 01:24:59 PST) Organization: Adequate Reply-To: thomas.nagy@home.com NNTP-Posting-Date: Tue, 09 Nov 1999 01:24:59 PST Newsgroups: comp.lang.pascal.delphi.misc,borland.public.delphi.winapi