Create image from Form
Deutsch · English
The following units are required for the examples:
...
uses
Graphics, Controls, Clipbrd, Forms, ...
...This function creates a screenshot from the submitted form:
...
uses
Forms, Graphics, Controls, ...
...
Procedure subCreateFormImage(Form: TForm; outBitmap: TBitmap);
var
Width: Integer;
Height: Integer;
Rectangle: TRect;
begin
Width := Form.Width;
Height:= Form.Height;
Rectangle:= Rect(0, 0, width, height);
Bitmap.Width := width;
Bitmap.Height:= height;
Bitmap.Canvas.CopyRect(rectangle, form.Canvas, rectangle);
end;Demonstration of how the above function can be used:
...
uses
Clipbrd, ...;
...
procedure test;
var
Bitmap: TBitMap;
begin
...
// Requests the memory for the bitmap
Bitmap := TBitmap.Create;
// Calls the function to create the screen printout / screenshot
subCreateFormImage(Form1, Bitmap);
// Example 1: Assigns the bitmap to an image
image1.Picture.Assign(bitmap);
// Example 2: Assigns the bitmap to the clipboard
Clipboard.Assign(bitmap);
// Releases the memory for the bitmap
FreeAndNil(bitmap)
...
end;
...From the Free Pascal wiki, page "Create image from Form", as it stood on 2020-02-12 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
