In a previous post some code along the lines of the "steema" code below was suggested.. it does not cope with the problem of saving the full image if some nodeshapes are at negative coordinates.
I really need that ability. By experimentation I have come up with another mechanism which seems to work but I think there could be buffering issues.
Could you please review, test and comment. Also show me how to save to jpg using the steema export approach
thanks
procedure TForm1.btnTrySteemaSaveToBitmapCodeClick(Sender: TObject);
{
save whole tree image to file
Two significant problems with this
a) it does not work - does not get the whole image
if ANY nodes have negative co-ordinates
b) it is not clear how to get specific ExportFormat objects
( eg jpeg) if they are not already in the TExportFormats list
}
var t: Integer;
tmpExp: TTeeExportFormat;
begin
tree1.FullExpandCollapse(True);
tree1.invalidate; application.processmessages;
// move to top left
tree1.perform(WM_VSCROLL, SB_TOP, 0);
tree1.perform(WM_HSCROLL, SB_LEFT, 0); // not SB_TOP as suggested in Steema support message
// grab the jpeg ? exporter
for t := 0 to TeeExportFormats.Count - 1 do begin
tmpExp := TeeExportFormats[t].Create;
if pos('*.bmp',tmpExp.FileFilter) > 0 then begin
// a kludgy way of detecting whether we have a bmp exporter
// dk how to register a jpg exporter
tmpExp.Panel := tree1;
tmpExp.Width :=tree1.totalbounds.right+5; // margin of 5 pixels
tmpExp.Height :=tree1.totalbounds.bottom+5; // margin of 5 pixels
tmpExp.SaveToFile(ExtractFilePath(Application.Exename)+'test'+inttostr(getTickCount)+'.bmp');
end;
dsmemo1.out(tmpExp.FileFilter);
tmpExp.Free;
end;
end;
procedure TForm1.btnSaveFullTreeImageClick(Sender: TObject);
{
this "works" but I am not sure how bulletproof it is
}
var r: Trect;
begin
tree1.perform(WM_VSCROLL, SB_TOP, 0);
tree1.perform(WM_HSCROLL, SB_LEFT, 0); // not SB_TOP as suggested in Steema support message
Tree1.Page.Border.Visible := false;
r := tree1.TotalBounds;
// adjust the bounds rectangle so the top left is (0,0)
r := rect(0, 0, r.right - r.left + 1, r.bottom - r.top + 1);
application.processmessages;
sleep(0); // so our next timeslice will be full
tree1.SaveToBitmapFile(ExtractFilePath(Application.Exename)+'test'+inttostr(getTickCount)+'.bmp',
r);
application.processmessages;
sleep(1000); // so we don't go back to updating the buffers straightaway
application.processmessages;
end;
saving full tree image - even with negative nodes
-
- Newbie
- Posts: 20
- Joined: Sat Oct 04, 2003 4:00 am
Hi,
You can export in jpeg through the TJpegExportFormat. eg a very rudimantary way:
Be sure to add TeeJPeg in the uses section
Regards,
tom
You can export in jpeg through the TJpegExportFormat. eg a very rudimantary way:
Code: Select all
procedure TForm1.Button4Click(Sender: TObject);
var ExportFormat : TJPEGExportFormat;
begin
ExportFormat := TJPEGExportFormat.Create;
try
ExportFormat.Panel := Tree1;
ExportFormat.Width := Tree1.TotalBounds.Right;
ExportFormat.Height := Tree1.TotalBounds.Bottom;
ExportFormat.SaveToFile('c:\tree.jpg');
finally
FreeAndNil(ExportFormat);
end;
end;
Regards,
tom
-
- Newbie
- Posts: 20
- Joined: Sat Oct 04, 2003 4:00 am