Sign in Join
Wiki copytemporary

Create image from Form: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Create image from Form

OldNewLine
1+The following [[Unit|units]] are required for the examples:
2+
3+``` pascal
4+ ...
5+
6+ uses
7+ Graphics, Controls, Clipbrd, Forms, ...
8+
9+ ...
10+```
11+
12+This function creates a screenshot from the submitted form:
13+
14+``` pascal
15+ ...
16+
17+ uses
18+ Forms, Graphics, Controls, ...
19+
20+ ...
21+
22+ Procedure subCreateFormImage(Form: TForm; outBitmap: TBitmap);
23+ var
24+ Width: Integer;
25+ Height: Integer;
26+ Rectangle: TRect;
27+
28+ begin
29+
30+ Width := Form.Width;
31+ Height:= Form.Height;
32+ Rectangle:= Rect(0, 0, width, height);
33+
34+ Bitmap.Width := width;
35+ Bitmap.Height:= height;
36+ Bitmap.Canvas.CopyRect(rectangle, form.Canvas, rectangle);
37+
38+ end;
39+```
40+
41+Demonstration of how the above function can be used:
42+
43+``` pascal
44+ ...
45+
46+ uses
47+ Clipbrd, ...;
48+
49+ ...
50+
51+ procedure test;
52+ var
53+ Bitmap: TBitMap;
54+
55+ begin
56+
57+ ...
58+
59+ // Requests the memory for the bitmap
60+ Bitmap := TBitmap.Create;
61+
62+ // Calls the function to create the screen printout / screenshot
63+ subCreateFormImage(Form1, Bitmap);
64+
65+ // Example 1: Assigns the bitmap to an image
66+ image1.Picture.Assign(bitmap);
67+
68+ // Example 2: Assigns the bitmap to the clipboard
69+ Clipboard.Assign(bitmap);
70+
71+ // Releases the memory for the bitmap
72+ FreeAndNil(bitmap)
73+
74+ ...
75+
76+ end;
77+
78+ ...
79+```
80+
81+---
82+*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](/wiki-contact).*

Back to history