Using Canvases for Drawing
Go Up to Using graphics in components Index
The canvas class encapsulates graphics controls at several levels, including high-level functions for drawing individual lines, shapes, and text. The Vcl.Graphics.TCustomCanvas class defines an abstract base for all canvas objects defined in the Visual Component Library. Most controls in the VCL have an associated canvas object; exception are controls that, under the hood, bind to Windows controls (such as Vcl.StdCtrls.TButton) and controls that use the parent's canvas for drawing (such as Vcl.ExtCtrls.TPaintBox).
Vcl.Graphics.TCustomCanvas has two primary descendants:
- Vcl.Graphics.TCanvas, that wraps the Windows GDI device contexts (HDCs).
- Vcl.Direct2D.TDirect2DCanvas, that wraps the Windows Direct2D API.
Note that all VCL controls use the Vcl.Graphics.TCanvas descendant, because most Windows operating
systems do not support Direct2D canvas. The only Windows version that supports Vcl.Direct2D.TDirect2DCanvas is Windows 7.
As a concept, the canvas is split into three levels of abstraction: High level, Intermediate level, and Low level. Each
level defines a functionality set. The High level functionality is available to all canvases, regardless of implementation details. The Intermediate level stays semantically identical between canvas implementations but may differ in the exposed public interface. Finally, the Low level exposes functionality that depends on the implementation.
The following table summarizes the three levels of abstraction. Consider it a reference, because there are functions defined as high level but still not implemented in all canvas descendants.
High-level functionality:
Operation | Tools |
---|---|
Drawing lines and shapes |
Methods such as MoveTo, LineTo, Rectangle, and Ellipse |
Displaying and measuring text |
TextOut, TextHeight, TextWidth, and TextRect methods |
Filling areas |
FillRect and FloodFill methods |
Intermediate-level functionality:
Operation | Tools |
---|---|
Customizing text and graphics |
Pen, Brush, and Font properties |
Low-level functionality:
Operation | Tools |
---|---|
Calling Windows GDI functions |
Handle property (Vcl.Graphics.TCanvas) |
Calling Windows Direct2D functions (Vcl.Direct2D.TDirect2DCanvas) |
RenderTarget property |
Manipulating pixels |
Pixels property (Vcl.Graphics.TCanvas) |
Copying and merging images |
Draw, StretchDraw, BrushCopy, and CopyRect methods; CopyMode property (Vcl.Graphics.TCanvas) |
Advanced drawing operations |
DrawEllipse, DrawGeometry, FillRectangle (Vcl.Direct2D.TDirect2DCanvas) |
See Also
- Using the Canvas
- Using the Direct2D Canvas
- Vcl.Graphics.TCustomCanvas
- Vcl.Graphics.TCanvas
- Vcl.Controls.TControlCanvas
- Vcl.Direct2D.TDirect2DCanvas