Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Delphi 6中将TVirtualStringTree的所有节点保存为BMP?_Delphi_Tvirtualstringtree - Fatal编程技术网

如何在Delphi 6中将TVirtualStringTree的所有节点保存为BMP?

如何在Delphi 6中将TVirtualStringTree的所有节点保存为BMP?,delphi,tvirtualstringtree,Delphi,Tvirtualstringtree,我使用Delphi6.0,我有TPanel,它包含TVirtualStringTree,它包含许多节点(多于一个屏幕) 我需要将此面板(包含所有节点)作为图片保存到BMP 我使用此方法保存面板: procedure TfrmDidTreeTime.cmSaveGantClick(Sender: TObject); var bmp : tBitmap; cnt : Integer; Dc : HDC; R : TRect; be

我使用Delphi6.0,我有TPanel,它包含TVirtualStringTree,它包含许多节点(多于一个屏幕)

我需要将此面板(包含所有节点)作为图片保存到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;
但此方法仅保存屏幕上显示的节点,但我需要保存所有节点。

过程TfrmDidTreeTime.cmSaveDidTreeTimeClick(发送方:TObject);
procedure TfrmDidTreeTime.cmSaveDidTreeTimeClick(Sender: TObject);
var
        bmp_total: tBitmap;
        bmp_current : tBitmap;

        r: TRect;
        dc: HDC;

        date_start: TDateTime;
        h: integer;

        bmp_current_position: integer;
        scroll_position_current: integer;
        scroll_position_total: integer;
        screen_count: integer;
begin
        inherited;

        date_start := dtpDateStart.Value;

        dc := GetDC (tvDidTimeTree.handle);
        r := tvDidTimeTree.boundsRect;

        bmp_total := tBitmap.create;
        bmp_total.width := r.Right - r.Left - sbxVertical.Width - 3;
        h := r.Bottom - r.Top - tvDidTimeTree.Header.Height;
        if h < 0 then
                h := 0;

        SendMessage(tvDidTimeTree.Handle, WM_VSCROLL, SB_BOTTOM, 0);

        scroll_position_total := GetScrollPos(tvDidTimeTree.Handle, sb_Vert);
        screen_count := round(scroll_position_total / h);

        bmp_total.Height := h * (screen_count + 1);
        bmp_current_position := 0;

        SendMessage(tvDidTimeTree.Handle, WM_VSCROLL, SB_TOP, 0);

        tvDidTimeTree.Repaint;

        while (scroll_position_current < scroll_position_total) do
        begin
                r := tvDidTimeTree.boundsRect;
                dc := GetDC (tvDidTimeTree.handle);

                bmp_current := tBitmap.create;
                bmp_current.width := r.Right - r.Left - sbxVertical.Width - 3;
                bmp_current.Height := h - 5;

                Bitblt(bmp_total.canvas.handle, 0, bmp_current_position, bmp_current.Width, bmp_current.height, dc, r.left, r.top, srccopy);
                scroll_position_current := GetScrollPos(tvDidTimeTree.Handle, sb_Vert);

                SendMessage(tvDidTimeTree.Handle, WM_VSCROLL, SB_PAGEDOWN, 0);

                tvDidTimeTree.Repaint;

                bmp_current_position := bmp_current_position + bmp_current.Height;
        end;

        spdSaveGraph.DefaultExt := 'bmp';
        spdSaveGraph.FileName := DateToStr(date_start) + '—' + DateToStr(IncMonth(date_start, 1)) + '.bmp';
        spdSaveGraph.Filter := 'Bitmap Picture|*.bmp';

        if spdSaveGraph.Execute then
                bmp_total.saveToFile (spdSaveGraph.FileName);

        bmp_total.free;
end;
变量 bmp_总计:tBitmap; bmp_当前:tBitmap; r:TRect; dc:HDC; 开始日期:TDateTime; h:整数; bmp\u当前位置:整数; 滚动\u位置\u当前:整数; 滚动\u位置\u总计:整数; 屏幕计数:整数; 开始 继承; 开始日期:=dtpDateStart.Value; dc:=GetDC(tvDidTimeTree.handle); r:=tvDidTimeTree.boundsRect; bmp_总计:=tBitmap.create; bmp_total.width:=r.Right-r.Left-sbxVertical.width-3; h:=右下-右上-tvDidTimeTree.Header.Height; 如果h<0,则 h:=0; SendMessage(tvDidTimeTree.Handle,WM_VSCROLL,SB_BOTTOM,0); scroll\u position\u total:=GetScrollPos(tvDidTimeTree.Handle,sb\u Vert); 屏幕计数:=四舍五入(滚动位置总数/h); bmp_总高度:=h*(屏幕计数+1); bmp\u当前位置:=0; SendMessage(tvDidTimeTree.Handle,WM_VSCROLL,SB_TOP,0); tvDidTimeTree。重新绘制; 而(滚动位置\u当前<滚动位置\u总计)不 开始 r:=tvDidTimeTree.boundsRect; dc:=GetDC(tvDidTimeTree.handle); bmp_current:=tBitmap.create; bmp_current.width:=r.Right-r.Left-sbxVertical.width-3; bmp_当前高度:=h-5; Bitblt(bmp_total.canvas.handle,0,bmp_current_position,bmp_current.Width,bmp_current.height,dc,r.left,r.top,srcopy); scroll\u position\u current:=GetScrollPos(tvDidTimeTree.Handle,sb\u Vert); SendMessage(tvDidTimeTree.Handle,WM_VSCROLL,SB_PAGEDOWN,0); tvDidTimeTree。重新绘制; bmp_current_position:=bmp_current_position+bmp_current.Height; 结束; spdSaveGraph.DefaultExt:=“bmp”; spdSaveGraph.FileName:=DateToStr(date_start)+'-'+DateToStr(IncMonth(date_start,1))+'.bmp'; spdSaveGraph.Filter:=“位图图片|*.bmp”; 如果是spdSaveGraph,则执行 bmp_total.saveToFile(spdSaveGraph.FileName); bmp_total.free; 结束;
您将无法使用Bitblt将TVirualStringTree的内部内容保存到位图中。其主要原因是TVirtualStringTree仅将其部分内容呈现在其窗口上。它这样做是为了在有大量字符串时不会对性能产生影响。也许可以重写TVirtualStringTree默认的绘制方法,强制它将其全部内容绘制到BMP中。我自己从来没有这样做过