BGRABitmap tutorial 6

From Lazarus wiki
Revision as of 07:09, 26 March 2011 by Circular (talk | contribs) (mix join styles)
Jump to navigationJump to search

This tutorial shows you how to use different line styles and shapes.

Create a new project

Create a new project and add a reference to BGRABitmap, the same way as in the first tutorial.

Add a painting handler

With the object inspector, add an OnPaint handler and write : <delphi>procedure TForm1.FormPaint(Sender: TObject); var image: TBGRABitmap;

   c: TBGRAPixel;

begin

 image := TBGRABitmap.Create(ClientWidth,ClientHeight,ColorToBGRA(ColorToRGB(clBtnFace)));
 c := ColorToBGRA(ColorToRGB(clWindowText)); 
 image.RectangleAntialias(80,80,300,200,c,50);
 image.Draw(Canvas,0,0,True);
 image.free;

end;</delphi>

Run the program

This should draw a rectangle with a wide black pen.

BGRATutorial6a.png

Change join style

If you want round corners, you can specify : <delphi> image.JoinStyle := pjsRound;</delphi>

Run the program

This should draw a rectangle with a wide black pen with rounded corners.

BGRATutorial6b.png

Mix join styles

You can mix join styles for a rectangle like this: <delphi> image.FillRoundRectAntialias(80,80,300,200, 20,20, c, [rrTopRightSquare,rrBottomLeftSquare]); </delphi>

This function use round corners by default, but you can override it with square corners or bevel corners. You should obtain the following image.

BGRATutorial6e.png

Change pen style

You can draw a dotted line like this : <delphi> image.JoinStyle := pjsBevel;

   image.PenStyle := psDot;
   image.DrawPolyLineAntialias([PointF(40,200), PointF(120,100), PointF(170,140), PointF(250,60)],c,10);

</delphi>

You should obtain the following image. Notice that line begins with a round cap.

Tutorial6c.png

Change line cap

You can draw a polyline with a square cap like this : <delphi> image.JoinStyle := pjsBevel;

   image.LineCap := pecSquare;
   image.PenStyle := psSolid;
   image.DrawPolyLineAntialias([PointF(40,200), PointF(120,100), PointF(170,140), PointF(250,60)],c,10);

</delphi>

BGRATutorial6d.png

Previous tutorial (layers and masks)