Recent

Author Topic: Saving a tchart's image to a Jpeg file  (Read 10490 times)

Pi

  • Jr. Member
  • **
  • Posts: 75
Saving a tchart's image to a Jpeg file
« on: July 08, 2014, 08:17:45 pm »
Is there a simple way to save a Tchart's image to a Jpeg file?
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

wp

  • Hero Member
  • *****
  • Posts: 13646
Re: Saving a tchart's image to a Jpeg file
« Reply #1 on: July 08, 2014, 08:26:57 pm »
Code: [Select]
  Chart1.SaveToFile(TJPEGImage, 'MyImage.jpg');

See also the demo project in components/tachart/demo/save of your lazarus installation, or http://wiki.lazarus.freepascal.org/TAChart_Demos#save

Pi

  • Jr. Member
  • **
  • Posts: 75
Re: Saving a tchart's image to a Jpeg file
« Reply #2 on: July 08, 2014, 08:41:01 pm »
Code: [Select]
  Chart1.SaveToFile(TJPEGImage, 'MyImage.jpg');

See also the demo project in components/tachart/demo/save of your lazarus installation, or http://wiki.lazarus.freepascal.org/TAChart_Demos#save
Thanks. I looked in the demo program you said and found the code similar to above (I didn't see the bit of code in the post before) :). That's what I wanted thanks.

Is there a way of changing the compression ratio / compression quality/file size of the jpeg of the saved chart (eg. I don't mind if the file size of the jpeg gets bigger)?
If not it's okay.
« Last Edit: July 08, 2014, 08:42:34 pm by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

wp

  • Hero Member
  • *****
  • Posts: 13646
Re: Saving a tchart's image to a Jpeg file
« Reply #3 on: July 08, 2014, 08:51:55 pm »
Not quite sure, but could you try this one:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  jpg: TRasterImage;
begin
  jpg := Chart1.SaveToImage(TJpegImage);
  try
    TJPegImage(jpg).CompressionQuality:=10;  //10% quality - pretty low-quality!
    jpg.SaveToFile('d:\temp\test.jpg');
  finally
    jpg.Free;
  end;
end;
The image looks pretty ugly, could be 10% quality - I guess it works.

Pi

  • Jr. Member
  • **
  • Posts: 75
Re: Saving a tchart's image to a Jpeg file
« Reply #4 on: July 08, 2014, 09:05:51 pm »
Yes, thanks a lot, that works  :)
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

 

TinyPortal © 2005-2018