SimpleGraph - Exporting Graph as Image

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

SimpleGraph - Exporting Graph as Image

Postby Kambiz » March 18th, 2006, 6:28 pm

Version 2.1 of SimpleGraph introduces a new method named CopyToGraphic. Using this method you can make a copy of the graph as a Graphic object.

For example, the following routine exports the graph as a JPEG file.

Code: Select all
uses
  JPEG;

procedure ExportGraphAsJPEG(SG: TSimpleGraph; const FileName: String);
var
  JPEG: TJPEGImage;
begin
  JPEG := TJPEGImage.Create;
  try
    SG.CopyToGraphic(JPEG);
    JPEG.SaveToFile(FileName);
  finally
    JPEG.Free;
  end;
end;


Or more generic, the following routine exports the graph in to a file as specified image format:

Code: Select all
procedure ExportGraphAsImage(SG: TSimpleGraph; GraphicClass: TGraphicClass;
  const FileName: String);
var
  Graphic: TGraphic;
begin
  Graphic := TGraphicClass.Create;
  try
    SG.CopyToGraphic(Graphic);
    Graphic.SaveToFile(FileName);
  finally
    Graphic.Free;
  end;
end;


Here is the example of usage for the above routine:

Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
  if SavePictureDialog1.Execute then
    ExportGraphAsImage(SimpleGraph1, TJPEGImage, SavePictureDialog1.FileName);
end;


You can use freeware GraphicEx library to extend image formats available in Delphi.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 5 guests

cron