after JPEG export of a zoomed chart an access violation occurs, when I try to unzoom the chart.
Here is my code example:
Code: Select all
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VclTee.TeeGDIPlus, Vcl.StdCtrls,
Vcl.ExtDlgs, VCLTee.TeEngine, Vcl.ExtCtrls, VCLTee.TeeProcs, VCLTee.Chart,
VCLTee.Series, Vcl.Imaging.jpeg;
type
TForm1 = class(TForm)
Chart1: TChart;
SavePictureDialog1: TSavePictureDialog;
ExportBtn: TButton;
Series1: TFastLineSeries;
procedure FormCreate(Sender: TObject);
procedure ExportBtnClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
(*___________________________________________________________________________*)
function GetChartJPEG(AChart:TCustomChart): TJPEGImage;
var tmpBitmap:TBitmap;
begin
Result:=TJPEGImage.Create; { <-- create a TJPEGImage }
tmpBitmap:=TBitmap.Create; { <-- create a temporary TBitmap }
try
tmpBitmap.Width :=AChart.Width; { <-- set the bitmap dimensions }
tmpBitmap.Height:=AChart.Height;
{ draw the Chart on the temporary Bitmap... }
AChart.Draw(tmpBitmap.Canvas,Rect(0,0,tmpBitmap.Width,tmpBitmap.Height));
{ set the desired JPEG options... }
With Result do
begin
GrayScale := False;
ProgressiveEncoding := True;
CompressionQuality := 100; // % 0 - 100
PixelFormat := jf24bit; // or jf8bit
ProgressiveDisplay := True;
Performance := jpBestQuality; // or jpBestSpeed
Scale := jsFullSize; // or jsHalf, jsQuarter, jsEighth
Smoothing := false;
{ Copy the temporary Bitmap onto the JPEG image... }
Assign(tmpBitmap);
end;
finally
tmpBitmap.Free; { <-- free the temporary Bitmap }
end;
end;
procedure TForm1.ExportBtnClick(Sender: TObject);
var
FName: string;
begin
SavePictureDialog1.Filter := 'JPG-Datei (*.jpg)|*.jpg';
if not SavePictureDialog1.Execute then Exit;
FName := SavePictureDialog1.FileName;
if ExtractFileExt(FName) = '' then FName := FName + '.jpg';
with GetChartJPEG(Chart1) do begin
SaveToFile(FName); { <-- save the JPEG to disk }
Free; { <-- free the temporary JPEG object }
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(500);
end;
end.
Has anybody an idea why it happens?
Thanks
Juergen