summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fcl-image/examples/drawing.pp
blob: 518e867b4340734ff8d6e6167dbb6fdb5584b664 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{$mode objfpc}{$h+}
program Drawing;

uses classes, sysutils,
     FPImage, FPCanvas, FPImgCanv, ftFont,
     FPWritePNG, FPReadPNG;

const
  MyColor : TFPColor = (Red: $7FFF; Green: $0000; Blue: $FFFF; Alpha: alphaOpaque);

procedure DoDraw;
var canvas : TFPcustomCAnvas;
    ci, image : TFPCustomImage;
    writer : TFPCustomImageWriter;
    reader : TFPCustomImageReader;
    f : TFreeTypeFont;
begin
  image := TFPMemoryImage.Create (100,100);
  ci := TFPMemoryImage.Create (20,20);
  Canvas := TFPImageCanvas.Create (image);
  Writer := TFPWriterPNG.Create;
  reader := TFPReaderPNG.Create;
  with TFPWriterPNG(Writer) do
    begin
    indexed := false;
    wordsized := false;
    UseAlpha := false;
    GrayScale := false;
    end;
  try
//    ci.LoadFromFile ('test.png', reader);
    with Canvas as TFPImageCanvas do
      begin
      pen.mode := pmCopy;
      pen.style := psSolid;
      pen.width := 1;
      pen.FPColor := colred;
      with pen.FPColor do
        red := red div 4;
      Ellipse (10,10, 90,90);

      pen.style := psDashDot;
      pen.FPColor := colred;
      HashWidth := 10;
      Ellipse (10,10, 90,90);

      with pen.FPColor do
        begin
        red := red div 2;
        green := red div 4;
        blue := green;
        end;
      pen.style := psSolid;
      RelativeBrushImage := true;
{
      brush.image := ci;
      brush.style := bsimage;
      with brush.FPColor do
        green := green div 2;
      Ellipse (11,11, 89,89);
}

      brush.style := bsSolid;
      brush.FPColor := MyColor;
      pen.style := psSolid;
      pen.width := 3;
      pen.FPColor := colSilver;
      ellipse (30,35, 70,65);

      pen.width := 1;
      pen.FPColor := colCyan;
      ellipseC (50,50, 1,1);

      InitEngine;
      F:=TFreeTypeFont.Create;
      F.Angle:=0.15;
      Font:=F;
//      Font.Name:='/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf';
      Font.Name:='/home/michael/Documents/arial.ttf';
      Font.Size:=10;
      Font.FPColor:=colWhite;
//      Font.Orientation:=900;
      
      Canvas.TextOut(10,90,'o');
      end;
      writeln ('Saving to inspect !');
    image.SaveToFile ('DrawTest.png', writer);
  finally
    Canvas.Free;
    image.Free;
    writer.Free;
    ci.free;
    reader.Free;
  end;
end;

begin
//  DefaultFontPath := '/usr/share/fonts/truetype/ttf-dejavu/';
  DoDraw;

end.