I need to create an enlarged copy of a chart and copy it into an excel sheet.
If I do this:
TeeSaveToJPEGFile( Chart1,
'c:\Temp.jpg',
False, // not gray scale
jpBestQuality,
95, // compression
Round(513*1.25),
Round(497*1.25) );
The result is that the chart that ends up in the excel sheet does not have very good resolution.
However, if in the app where the chart is displayed to the user, I stretch the chart manually and then do "TeeSaveToJPEG" and then "insert pic" in excel, I get a much better image.
How can I do this in code please?
Thanks
copy chart to excel
Hi mc,
Could you take a look at this example and see if it's useful at your end?
Could you take a look at this example and see if it's useful at your end?
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
Function GetChartJPEG(AChart:TCustomChart):TJPEGImage;
var tmpBitmap:TBitmap;
tmpChart: TChart;
i:integer;
begin
result:=TJPEGImage.Create; { <-- create a TJPEGImage }
tmpBitmap:=TBitmap.Create; { <-- create a temporary TBitmap }
tmpChart := TChart.Create(AChart.Parent);
try
tmpChart.Assign(AChart);
for i := 0 to AChart.SeriesCount - 1 do
CloneChartSeries(AChart.Series[i]).ParentChart := tmpChart;
tmpChart.Width := trunc(AChart.Width*1.25);
tmpChart.Height := trunc(AChart.Height*1.25);
tmpBitmap.Width :=tmpChart.Width; { <-- set the bitmap dimensions }
tmpBitmap.Height:=tmpChart.Height;
{ draw the Chart on the temporary Bitmap... }
tmpChart.Draw(tmpBitmap.Canvas,Rect(0,0,tmpBitmap.Width,tmpBitmap.Height));
{ set the desired JPEG options... }
With result do
begin
GrayScale :=False;
ProgressiveEncoding :=True;
CompressionQuality :=95; // % 0 - 100
PixelFormat :=jf24bit; // or jf8bit
ProgressiveDisplay :=True;
Performance :=jpBestQuality; // or jpBestSpeed
Scale :=jsFullSize; // or jsHalf, jsQuarter, jsEighth
Smoothing :=True;
{ Copy the temporary Bitmap onto the JPEG image... }
Assign(tmpBitmap);
end;
finally
tmpBitmap.Free; { <-- free the temporary Bitmap }
tmpChart.Free;
end;
end;
begin
With GetChartJPEG(Chart1) do
try
SaveToFile('C:\tmp\myJPEGChart.jpg'); { <-- save the JPEG to disk }
finally
Free; { <-- free the temporary JPEG object }
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi mc,
Have you tried increasing the jpg file size befire exporting it so that you have better resolution?
Thanks in advance.
Have you tried increasing the jpg file size befire exporting it so that you have better resolution?
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |