Description


TCanvas provides properties and methods that assist in creating an image by:


  • Specifying the type of brush, pen, and font to use.
  • Drawing and filling a variety of shapes and lines.
  • Writing text.
  • Rendering graphic images.





Class Methods and Properties

 Methods and Properties

 Description

 procedure Arc (X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer)

 Use Arc to draw an elliptically curved line with the current Pen. The arc traverses the perimeter of an ellipse that is bounded by the points (X1,Y1) and (X2,Y2). The arc is drawn following the perimeter of the ellipse, counterclockwise, from the starting point to the ending point. The starting point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X3,Y3). The ending point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X4, Y4).

 procedure ArcTo (X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer)

 Draws an arc on the image along the perimeter of the ellipse bounded by the specified rectangle. The arc traverses the perimeter of an ellipse that is bounded by the points (X1,Y1) and (X2,Y2). The arc is drawn following the perimeter of the ellipse, counterclockwise, from the starting point to the ending point. The starting point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X3,Y3). The ending point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X4, Y4).

 procedure AngleArc (X, Y: Integer; Radius: Cardinal; StartAngle, SweepAngle: Single)

 Draws an arc on the image along the perimeter of the circle defined by the parameters. The AngleArc method draws a line from the current position to the starting point of the arc and then a counterclockwise circular arc to the arc endpoint. The arc traverses the perimeter of a circle whose center lies at (X,Y) and whose radius is Radius. The arc is drawn following the perimeter of the circle, counterclockwise, from the StartAngle with a sweep angle of SweepAngle.


If the sweep angle is greater than 360 degrees, the entire circle is drawn and part of the arc is drawn multiple times.

 property Brush: TBrush

 Determines the color and pattern for filling graphical shapes and backgrounds.

    property Brush.Color: TColor

 Indicates the color of the brush.

    property Brush.Style: TBrushStyle

 Specifies the pattern for the brush. Available values: bsSolid, bsClear, bsHorizontal, bsVertical, bsFDiagonal, bsBDiagonal, bsCross, bsDiagCross

 procedure Chord (X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer)

 Draws a closed figure represented by the intersection of a line and an ellipse. Use Chord to create a shape that is defined by an arc and a line that joins the endpoints of the arc. The chord consists of a portion of an ellipse that is bounded by the points (X1,Y1) and (X2,Y2). The ellipse is bisected by a line that runs between the points (X3,Y3) and (X4,Y4).

 procedure CopyRect (destLeft, destTop, destRight, destBottom: integer; Canvas: TCanvas; srcLeft, srcTop, srcRight, srcBottom: integer

 Copies part of an image from another canvas into the canvas. Use CopyRect to transfer part of the image on another canvas to the image of the TCanvas object. Dest specifies the rectangle on the canvas where the source image will be copied. The Canvas parameter specifies the canvas with the source image. Source specifies a rectangle bounding the portion of the source canvas that will be copied.

 procedure Draw (X, Y: Integer; Graphic: TGraphic)

 Renders the graphic specified by the Graphic parameter on the canvas at the location given by the coordinates (X, Y).

 procedure Draw2 (X, Y: Integer; Graphic: TGraphic; Opacity: Byte)

 Renders the graphic specified by the Graphic parameter on the canvas at the location given by the coordinates (X, Y). The Opacity parameter allows you to set the level of transparency (value from 0 to 255).

 procedure Ellipse (X1, Y1, X2, Y2: Integer)

 Draws the ellipse defined by a bounding rectangle on the canvas. The top left point at pixel coordinates (X1, Y1) and the bottom right point at (X2, Y2). If the bounding rectangle is a square, a circle is drawn.The ellipse is outlined using the value of Pen, and filled using the value of Brush.

 property Font: TFont

 The property is responsible for the appearance of the text, which can be output using the TextOut method.

 procedure LineTo (X, Y: Integer)

 Draws a line on the canvas from PenPos to the point specified by X and Y, and sets the pen position to (X, Y).

 procedure MoveTo (X, Y: Integer)

 Changes the current drawing position to the point (X,Y).

 property Pen: TPen

 Specifies the kind of pen the canvas uses for drawing lines and outlining shapes.

    property Pen.Color: TColor

 Determines the color used to draw lines on the canvas.

    property Pen.Style: TPenStyle

 Determines the style in which the pen draws lines. Available values: psSolid, psDash, psDot, psDashDot, psDashDotDot, psClear, psInsideFrame

    property Pen.Width: Integer

 Specifies the width of the pen in pixels.

 procedure Pie (X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer)

 Draws a pie-shaped section of the ellipse bounded by the rectangle (X1, Y1) and (X2, Y2) on the canvas.

 property Pixels (X, Y: Integer): TColor

 Specifies the color of the pixels within the current ClipRect. Read Pixels to learn the color on the drawing surface at a specific pixel position within the current clipping region. If the position is outside the clipping rectangle, reading the value of Pixels returns -1. Write Pixels to change the color of individual pixels on the drawing surface. Use Pixels for detailed effects on an image.

 procedure Rectangle (X1, Y1, X2, Y2: Integer)

 Draws a rectangle on the canvas.

 procedure RoundRect (X1, Y1, X2, Y2, X3, Y3: Integer)

 Draws a rectangle with rounded corners on the canvas. Use RoundRect to draw a rounded rectangle using Pen and fill it with Brush. The rectangle will have edges defined by the points (X1,Y1), (X2,Y1), (X2,Y2), (X1,Y2), but the corners will be shaved to create a rounded appearance. The curve of the rounded corners matches the curvature of an ellipse with width X3 and height Y3.

 procedure TextOut (X, Y: Integer; const Text: string)

 Writes a string on the canvas, starting at the point (X,Y), and then updates the PenPos to the end of the string. The string will be written using the current value of Font.

 property Handle: Integer

 Specifies the handle for this canvas.




Example


    Form1.Image1.Canvas.Brush.Style := bsClear;
    Form1.Image1.Canvas.Font.Orientation := 270;
    Form1.Image1.Canvas.MoveTo(50, 50);
    Form1.Image1.Canvas.LineTo(100, 100);
    Form1.Image1.Canvas.TextOut(150, 150, 'Texts');
    Form1.Image1.Canvas.Ellipse(30, 30, 45, 45);