1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
{
This demo shows how you can manipulate the data of a TfpgImage
directly.
}
program bitmaptest;
{$mode objfpc}{$H+}
uses
Classes,
SysUtils,
fpg_base,
fpg_main,
fpg_imgfmt_bmp,
fpg_form;
type
TMainForm = class(TfpgForm)
private
img: TfpgImage;
procedure FormPaint(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
{ TMainForm }
procedure TMainForm.FormPaint(Sender: TObject);
var
i, j: integer;
begin
if not Assigned(img) then // we only need to create the image once
begin
img := TfpgImage.Create;
img.AllocateImage(32, 256, 256);
// populate the bitmap with pretty colors :-)
for j := 0 to 255 do
for i := 0 to 255 do
PLongWord(img.ImageData)[j * 256 + i] := (i shl 16) or (j shl 8);
img.UpdateImage; // now only do we allocate OS resources
end;
Canvas.DrawImage(0, 0, img);
end;
constructor TMainForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SetPosition(100, 100, 256, 256);
WindowTitle := 'fpGUI Bitmap Test';
WindowPosition := wpOneThirdDown;
Sizeable := False;
OnPaint := @FormPaint;
end;
destructor TMainForm.Destroy;
begin
img.Free;
inherited Destroy;
end;
procedure MainProc;
var
frm: TMainForm;
begin
fpgApplication.Initialize;
frm := TMainForm.Create(nil);
frm.Show;
fpgApplication.Run;
frm.Free;
end;
begin
MainProc;
end.
|