Sign in Join
Wiki copytemporary

Revision 1 of 1, by Trev on 2-12-2020. The page as it is now.

Create image from Form

The following units are required for the examples:

pascal
  ...
  
 uses
   Graphics, Controls, Clipbrd, Forms, ...

   ...

This function creates a screenshot from the submitted form:

pascal
  ...

 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:

pascal
  ...

 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.