Hi, so könnt ihr ein Canvas, auf das ihr beispielsweise mit Rectangle & Co. gezeichnet habt, als Grafik abspeichern:
Delphi-Quellcode:
procedure SaveCanvas(SaveCanvas: TCanvas; FileName: string);
var
Bmp: TBitmap;
MyRect: TRect;
begin
Bmp:= TBitmap.Create;
try
MyRect := SaveCanvas.ClipRect;
Bmp.Width := MyRect.Right - MyRect.Left;
Bmp.Height := MyRect.Bottom - MyRect.Top;
Bmp.Canvas.CopyRect(MyRect, SaveCanvas, MyRect);
Bmp.SaveToFile(FileName);
finally
FreeAndNil(Bmp);
end;
end;
Aufgerufen wird die Prozedur folgendermaßen:
SaveCanvas(PaintBox1.Canvas, 'D:\Canvas von PaintBox1.bmp');