Exporting 2 Charts using JPEGExportFormat

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Andrew S
Newbie
Newbie
Posts: 42
Joined: Wed Jul 28, 2004 4:00 am

Exporting 2 Charts using JPEGExportFormat

Post by Andrew S » Thu Nov 18, 2004 5:36 pm

This may be a bit naive, but I don't play around with this sort of thing much. Basically, I'm trying to export 2 charts to one jpeg file. I have the basic idea of what I'm trying to do; Copy the chart canvases to one bitmap, then load it into the jpeg and save it. I keep getting the error "Panel property not set". Can anyone give me some suggestions? As far as i can figure, I would need to set the panel property to be one of my two charts, which obviously wouldn't achieve the results I'm looking for. I've included a sample of what I'm trying to do...

I know the bitmap is what I want, because if I do a "bitmapImage.saveToFile" before I load it into the stream, it looks correct.

procedure TFMain.saveToJPEG(fileName : TFileName);
var
jpegImage : TJPEGExportFormat;
bitmapImage : TBitmap;
imageStream : TMemoryStream;
begin
bitmapImage := TBitmap.Create;
imageStream := TMemoryStream.Create;
jpegImage := TJPEGExportFormat.Create;
bitmapImage.Width := max(RSSIChart.Width, SINADRChart.Width);
bitmapImage.Height := SINADRChart.Height + RSSIChart.Height;
bitmapImage.Canvas.StretchDraw(Rect(RSSIChart.ClientRect.Left, RSSIChart.ClientRect.Top, RSSIChart.ClientRect.Right, RSSIChart.ClientRect.Bottom), RSSIChart.TeeCreateMetaFile(True, RSSIChart.ClientRect));
bitmapImage.Canvas.StretchDraw(Rect(SINADRChart.ClientRect.Left, SINADRChart.ClientRect.Top + RSSIChart.ClientHeight, SINADRChart.ClientRect.Right, SINADRChart.ClientRect.Bottom + RSSIChart.ClientHeight), SINADRChart.TeeCreateMetaFile(True, SINADRChart.ClientRect));
bitmapImage.SaveToStream(imageStream);
jpegImage.Jpeg.LoadFromStream(imageStream);
jpegImage.Height := SINADRChart.Height + RSSIChart.Height;
jpegImage.Width := max(RSSIChart.Width, SINADRChart.Width);
jpegImage.SaveToFile(fileName);
bitmapImage.Free;
imageStream.Free;
jpegImage.Free;
end;

Thanks in advance for any assistance,

Andrew

Andrew S
Newbie
Newbie
Posts: 42
Joined: Wed Jul 28, 2004 4:00 am

Post by Andrew S » Thu Nov 18, 2004 7:40 pm

Actually, I wound up figuring it out myself, using the JPEG unit. Just get rid of the memory stream variable, declare a variable as a TJPEGImage, and use the following.

jpegImage.Assign(bitmapImage);
jpegImage.CompressionQuality := 85;
jpegImage.Compress;
jpegImage.SaveToFile(fileName);

... I knew it would be a pretty simple solution. Sorry for the false alarm.

Post Reply