Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Grafik / Sound / Multimedia (https://www.delphipraxis.net/21-library-grafik-sound-multimedia/)
-   -   Delphi Canvas als Grafik speichern (https://www.delphipraxis.net/62981-canvas-als-grafik-speichern.html)

Matze 12. Feb 2006 12:46


Canvas als Grafik speichern
 
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:

Delphi-Quellcode:
SaveCanvas(PaintBox1.Canvas, 'D:\Canvas von PaintBox1.bmp');


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:37 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz