[fpc-pascal]Easy graphics<

Michael Van Canneyt michael.vancanneyt at wisa.be
Thu Apr 22 22:09:25 CEST 2004


On Thu, 22 Apr 2004, Alan Mead wrote:

> What is the easiest way to create PNG or JPG images from within a FPC
> program?  Ideally, in a cross-platform way although I mostly use
> Linux.  Thanks!
Very easy.

Roughly like this:

uses fpimage,fpcanvas,fpwritepng, fpwritejpg;

Var
  Image : TMemoryImage;
  Canvas : TFPimageCanvas;

begin
  // Create image,
  Image:=TMemoryImage.Create(640,480);
  Image.PaletteBased:=False;
  // Create canvas.
  Canvas:=TFPImageCanvas.Create(Image);
  Canvas.Pen.Color:=colRed;
  Canvas.Circle(100,100,50);
  Canvas.Rectangle(50,50,150,150);
  // Free canvas
  Canvas.Free;
  Image.SaveToFile('myfile.png'); // Write as png
  Image.SaveToFile('myfile.jpg'); // Alternatively, write as jpg
  // Free Image.
  Image.Free;
end.

See the fcl/image directory for all needed units.
Supported are bmp,png,jpg,xpm and PPM/PBM.

There is no documentation yet, but I can provide some examples and explanations.
This is fully cross-platform.

Michael.





More information about the fpc-pascal mailing list