Sign in Join
Wiki copytemporary

BGRABitmap tutorial 6: what changed

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

OldNewLine
11This tutorial shows you how to use different line styles and shapes.
22
33### Create a new project
44
55Create a new project and add a reference to [[BGRABitmap]], the same way as in [[BGRABitmap tutorial|the first tutorial]].
66
77### Add a painting handler
88
99With the object inspector, add an OnPaint handler and write:
1010
1111``` pascal
1212procedure TForm1.FormPaint(Sender: TObject);
1313var image: TBGRABitmap;
1414 c: TBGRAPixel;
1515begin
1616 image := TBGRABitmap.Create(ClientWidth, ClientHeight, clBtnFace);
1717 c := clWindowText;
1818
1919 image.RectangleAntialias(80,80,300,200, c, 50);
2020
2121 image.Draw(Canvas,0,0,True);
2222 image.free;
2323end;
2424```
2525
2626### Run the program
2727
2828This should draw a rectangle with a wide black pen.
2929
30-<figure>
31-<img src="BGRATutorial6a.png" title="BGRATutorial6a.png" />
32-<figcaption>BGRATutorial6a.png</figcaption>
33-</figure>
30+![](/wiki-images/0/06/BGRATutorial6a.png)
3431
3532### Change join style
3633
3734If you want round corners, you can specify:
3835
3936``` pascal
4037 image.JoinStyle := pjsRound;
4138```
4239
4340### Run the program
4441
4542This should draw a rectangle with a wide black pen with rounded corners.
4643
47-<figure>
48-<img src="BGRATutorial6b.png" title="BGRATutorial6b.png" />
49-<figcaption>BGRATutorial6b.png</figcaption>
50-</figure>
44+![](/wiki-images/3/34/BGRATutorial6b.png)
5145
5246### Mix join styles
5347
5448You can mix join styles for a rectangle like this:
5549
5650``` pascal
5751 image.FillRoundRectAntialias(80,80,300,200, 20,20, c, [rrTopRightSquare,rrBottomLeftSquare]);
5852```
5953
6054This function use round corners by default, but you can override it with square corners or bevel corners. You should obtain the following image.
6155
62-<figure>
63-<img src="BGRATutorial6e.png" title="BGRATutorial6e.png" />
64-<figcaption>BGRATutorial6e.png</figcaption>
65-</figure>
56+![](/wiki-images/5/54/BGRATutorial6e.png)
6657
6758### Change pen style
6859
6960You can draw a dotted line like this:
7061
7162``` pascal
7263 image.JoinStyle := pjsBevel;
7364 image.PenStyle := psDot;
7465 image.DrawPolyLineAntialias([PointF(40,200), PointF(120,100), PointF(170,140), PointF(250,60)],c,10);
7566```
7667
77-<table>
78-
79-<tr>
80-
81-<td bgcolor="#FFFFe0" style="border: 1px solid black; padding: 4px; text-align: center; border-radius:5px" width="30%">
82-
8368Note that the pen style can be defined independently of a bitmap by using the TBGRAPenStroker class of the BGRAPen[1](https://github.com/bgrabitmap/bgrabitmap/blob/master/bgrabitmap/bgrapen.pas) unit.
8469
85-</td>
86-
87-</tr>
88-
89-</table>
90-
9170You should obtain the following image. Notice that line begins with a round cap.
9271
93-<figure>
94-<img src="Tutorial6c.png" title="Tutorial6c.png" />
95-<figcaption>Tutorial6c.png</figcaption>
96-</figure>
72+![](/wiki-images/3/30/Tutorial6c.png)
9773
9874### Change line cap
9975
10076You can draw a polyline with a square cap like this:
10177
10278``` pascal
10379 image.JoinStyle := pjsBevel;
10480 image.LineCap := pecSquare;
10581 image.PenStyle := psSolid;
10682 image.DrawPolyLineAntialias([PointF(40,200), PointF(120,100), PointF(170,140), PointF(250,60)],c,10);
10783```
10884
109-<figure>
110-<img src="BGRATutorial6d.png" title="BGRATutorial6d.png" />
111-<figcaption>BGRATutorial6d.png</figcaption>
112-</figure>
85+![](/wiki-images/7/73/BGRATutorial6d.png)
11386
11487### Opened line drawing
11588
11689You can draw a line which is opened, i.e. the end of the line is rounded inside.
11790
11891``` pascal
11992 image.DrawPolyLineAntialias([PointF(40,200), PointF(120,100), PointF(170,140), PointF(250,60)],c,10,False);
12093```
12194
122-<figure>
123-<img src="BGRATutorial6f.png" title="BGRATutorial6f.png" />
124-<figcaption>BGRATutorial6f.png</figcaption>
125-</figure>
95+![](/wiki-images/2/2f/BGRATutorial6f.png)
12696
12797This way you can connect lines one after another without drawing the junction twice, which is useful with semi-transparent drawing. You can compare it like this:
12898
12999``` pascal
130100 c := BGRA(0,0,0,128);
131101
132102 image.DrawLineAntialias(40,150, 120,50, c, 10);
133103 image.DrawLineAntialias(120,50, 170,90, c, 10);
134104 image.DrawLineAntialias(170,90, 250,10, c, 10);
135105
136106 image.DrawLineAntialias(40,250, 120,150, c, 10, False);
137107 image.DrawLineAntialias(120,150, 170,190, c, 10, False);
138108 image.DrawLineAntialias(170,190, 250,110, c, 10, True);
139109```
140110
141-<figure>
142-<img src="Tutorial6g.png" title="Tutorial6g.png" />
143-<figcaption>Tutorial6g.png</figcaption>
144-</figure>
111+![](/wiki-images/8/8f/Tutorial6g.png)
145112
146113[[BGRABitmap tutorial 5|Previous tutorial (layers and masks)]] [[BGRABitmap tutorial 7|Next tutorial (splines)]]
147114
148115---
149116*From the Free Pascal wiki, page "BGRABitmap tutorial 6", as it stood on 2024-02-15 after a change by Circular, 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).*
150117Category: BGRABitmap
151118Category: Graphics

Back to history