-
Notifications
You must be signed in to change notification settings - Fork 59
Rendering TBIChart to PNG #21
Copy link
Copy link
Open
Description
Hello.
If I use the code below, I can save any TChart to PNG. Even one I create programmatically and has never been actually shown onscreen.
However, when I use this method on TBIChart.Chart, without the TBiChart being shown onscreen, the resulting PNG just has a black border and nothing else. I cannot see why this should not work, since TBITChart is just a TChart descendent.
If I show the TBiChart onscreen and then call the code below on the BiChart1.Chart, the resulting PNG is fine. Is there some method I can call to force the TBiChart.Chart to update itself so it can render to PNG even though it has not been shown on screen yet?
TChartHelper=class helper for TChart
public
procedure SaveToPNG(const aFileName:string; const aWidth:integer=-1; const aHeight:integer=-1);
end;
implementation
procedure TChartHelper.SaveToPNG(const aFileName:string; const aWidth:integer=-1; const aHeight:integer=-1);
var
PNGExport: TPNGExportFormat;
begin
PNGExport := TPNGExportFormat.Create;
try
PNGExport.Panel := self;
if aWidth>0 then
PNGExport.Width := aWidth
else
pngExport.Width := self.Width;
if aHeight>0 then
PNGExport.Height := aHeight
else
pngExport.Height:=self.Height;
PNGExport.SaveToFile(aFileName);
finally
PNGExport.Free;
end;
end;
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels