tpanel 내용을 인쇄하는 방법?
문제
나는 tpanel이 있습니다. 이 패널에는 타이밍 후손과 컨트롤이있는 다른 패널이 거의 없습니다. 실제로 그림에는 일부 다이어그램이 포함되어 있으며, 런타임이있는 추가 패널이 추가 정보를 제공하여 사용자에게 추가 정보를 제공합니다.
최근에 나는이 패널을 인쇄 할 수 있다면 좋을 것이라고 들었고, 형태로 나타나는대로 종이에 그것을 갖는 것이 좋을 것이라고 들었습니다. 어떤 단서, 어떻게 하는가?
해결책
인쇄 할 수있는 패널의 내용을 비트 맵에 복사하여 솔루션을 제공하는 오래된 USENET 게시물을 찾았습니다.
procedure TFormPrintWindows.ButtonPrintPanelClick(Sender: TObject);
var
Bitmap : TBitmap;
FromLeft : INTEGER;
FromTop : INTEGER;
PrintedWidth : INTEGER;
PrintedHeight: INTEGER;
begin
Printer.BeginDoc;
TRY
Bitmap := TBitmap.Create;
TRY
Bitmap.Width := Panel1.Width;
Bitmap.Height := Panel1.Height;
Bitmap.PixelFormat := pf24bit; // avoid palettes
// Copy the Panel area from the Form into a separate Bitmap
Bitmap.Canvas.CopyRect(Rect(0,0, Bitmap.Width,Bitmap.Height),
FormPrintWindows.Canvas,
Rect(Panel1.Left, Panel1.Top,
Panel1.Left + Panel1.Width-1,
Panel1.Top + Panel1.Height-1) );
// Assumes 10% left, right and top margin
// Assumes bitmap aspect ratio > ~0.75 for portrait mode
PrintedWidth := MulDiv(Printer.PageWidth, 80,100); // 80%
PrintedHeight := MulDiv(PrintedWidth, Bitmap.Height, Bitmap.Width);
FromLeft := MulDiv(Printer.PageWidth, 10,100); // 10%
FromTop := MulDiv(Printer.PageHeight,10,100); // 10%
PrintBitmap(Printer.Canvas,
Rect(FromLeft, FromTop,
FromLeft + PrintedWidth,
FromTop + PrintedHeight),
Bitmap);
FINALLY
Bitmap.Free
END;
FINALLY
Printer.EndDoc
END
end;
그리고 추가
//Source of Code:
//http://www.swissdelphicenter.ch/torry/showcode.php?id=744
//Which refers to a posting to borland.public.delphi.winapi by Rodney E Geraghty, 8/8/97.
procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
var
BitmapHeader: pBitmapInfo;
BitmapImage: Pointer;
HeaderSize: DWORD;
ImageSize: DWORD;
begin
GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
GetMem(BitmapHeader, HeaderSize);
GetMem(BitmapImage, ImageSize);
try
GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
StretchDIBits(Canvas.Handle,
DestRect.Left, DestRect.Top, // Destination Origin
DestRect.Right - DestRect.Left, // Destination Width
DestRect.Bottom - DestRect.Top, // Destination Height
0, 0, // Source Origin
Bitmap.Width, Bitmap.Height, // Source Width & Height
BitmapImage,
TBitmapInfo(BitmapHeader^),
DIB_RGB_COLORS,
SRCCOPY)
finally
FreeMem(BitmapHeader);
FreeMem(BitmapImage)
end
end {PrintBitmap};
다른 팁
Birger의 코드 예제의 PrintBitMap이 누락되었습니다. 누락 된 메소드를 추가하면 잘 작동합니다.
//Source of Code:
//http://www.swissdelphicenter.ch/torry/showcode.php?id=744
//Which refers to a posting to borland.public.delphi.winapi by Rodney E Geraghty, 8/8/97.
procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
var
BitmapHeader: pBitmapInfo;
BitmapImage: Pointer;
HeaderSize: DWORD;
ImageSize: DWORD;
begin
GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
GetMem(BitmapHeader, HeaderSize);
GetMem(BitmapImage, ImageSize);
try
GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
StretchDIBits(Canvas.Handle,
DestRect.Left, DestRect.Top, // Destination Origin
DestRect.Right - DestRect.Left, // Destination Width
DestRect.Bottom - DestRect.Top, // Destination Height
0, 0, // Source Origin
Bitmap.Width, Bitmap.Height, // Source Width & Height
BitmapImage,
TBitmapInfo(BitmapHeader^),
DIB_RGB_COLORS,
SRCCOPY)
finally
FreeMem(BitmapHeader);
FreeMem(BitmapImage)
end
end {PrintBitmap};
제휴하지 않습니다 StackOverflow