summaryrefslogtreecommitdiff
path: root/examples/gui/imgtest/bitmaptest.dpr
blob: 380aa07616abf3a78b48306f052458db38014574 (plain)
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
{
  This demo shows how you can manipulate the data of a TfpgImage
  directly.
}
program bitmaptest;

{$mode objfpc}{$H+}

uses
  Classes,
  SysUtils,
  gfxbase,
  fpgfx,
  gfx_imgfmt_bmp,
  gui_form;

type

  TMainForm = class(TfpgForm)
  private
    img: TfpgImage;
  protected
    procedure   HandlePaint; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
  end;


{ TMainForm }

procedure TMainForm.HandlePaint;
var
  i, j: integer;
begin
  Canvas.BeginDraw; // activate double buffering in time.
//  inherited HandlePaint;
  img.Free;
  img := TfpgImage.Create;
  img.AllocateImage(32, 256, 256);
  img.UpdateImage;
  // 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);
  Canvas.DrawImage(0, 0, img);
  Canvas.EndDraw;
end;

constructor TMainForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  SetPosition(100, 100, 256, 256);
  WindowTitle := 'fpGUI Bitmap Test';
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;
end;


begin
  MainProc;
end.