【发布时间】:2019-09-13 06:59:52
【问题描述】:
我使用 Delphi 6.0,并且我有 TPanel,其中包含 TVirtualStringTree,其中包含许多节点(超过 1 个屏幕)。
我需要将此面板(包含所有节点)作为图片保存到 BMP。
我用这个方法保存面板:
procedure TfrmDidTreeTime.cmSaveGantClick(Sender: TObject);
var
bmp : tBitmap;
cnt : Integer;
Dc : HDC;
R : TRect;
begin
inherited;
DC := GetDC ( pnlChart.handle);
R := pnlChart.boundsRect;
bmp := tBitmap.create;
bmp.width := R.Right-R.Left;
bmp.Height := R.Bottom - R.Top;
Bitblt(bmp.canvas.handle,0,0,bmp.Width,bmp.height,dc,r.left,r.top,srccopy);
spdSaveGraph.DefaultExt := 'bmp';
spdSaveGraph.FileName := 'Gant.bmp';
spdSaveGraph.Filter := 'Bitmap Picture|*.bmp';
if spdSaveGraph.Execute then
bmp.saveToFile (spdSaveGraph.FileName);
bmp.free;
end;
但是这种方法只保存屏幕上显示的节点,但我需要保存所有节点。
【问题讨论】:
-
您将无法使用 Bitblt 将 TVirualStringTree 的 nterie 内容保存到位图中。主要原因是 TVirtualStringTree 仅将其部分内容呈现到其 Windows 上。这样做是为了在您有大量字符串时不会影响性能。
-
也许你可以重写 TVirtualStringTree 默认的 Paint 方法来强制它把它的全部内容绘制到你的 BMP 中。我自己从来没有这样做过