Thread View: comp.lang.pascal.delphi.misc
1 messages
1 total messages
Started by Thomas Nagy
Tue, 09 Nov 1999 00:00
Printing bitmap: Nothing is printed. WHY?
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads