Canvas
Struct · namespace System.Ui · Since 0.32
struct CanvasDraws into an Image: everything is clipped to Clip, colors with an alpha below 255 are blended with what is
already there, and the edges of rounded rectangles, circles and lines are smooth. A canvas shares the pixels of its
image (an Image holds them by reference), so drawing changes the image.
var image = Image.Create(200, 100);var canvas = Canvas.Create(image);canvas.Clear(Color.White());canvas.FillRoundRect(Rect.Create(10, 10, 120, 30), 6, Color.FromRgb(40, 110, 220));canvas.Text(Font.Fixed7x13(), 20, 18, "Hello", Color.White());Fields
Section titled “Fields”| Name | Description |
|---|---|
Target |
The image that is drawn into. |
Clip |
Only pixels inside this rectangle are changed. |
Target
Section titled “Target”Image TargetThe image that is drawn into.
Rect ClipOnly pixels inside this rectangle are changed.
Static methods
Section titled “Static methods”| Name | Description |
|---|---|
Create |
A canvas for the whole image. |
Create
Section titled “Create”static Canvas Create(Image target)A canvas for the whole image.
Methods
Section titled “Methods”| Name | Description |
|---|---|
SetClip |
Restricts drawing to a rectangle (within the image). |
Clear |
Fills the whole image (ignoring the clip rectangle) with one color. |
Blend |
Blends one pixel: coverage 0 (nothing) to 255 (the color with its own alpha). |
FillRect |
Fills a rectangle. |
StrokeRect |
Draws the outline of a rectangle, width pixels thick, inside the rectangle. |
FillRoundRect |
Fills a rectangle with rounded corners of the given radius (smooth edges). |
StrokeRoundRect |
Draws the outline of a rounded rectangle, width pixels thick, inside the rectangle. |
FillCircle |
Fills a circle (smooth edge); the center may lie between pixels. |
Line |
Draws a line width pixels thick with round ends (smooth edges); coordinates may lie between pixels. |
Text |
Draws text with its top left corner at (x, y) and returns its width. |
DrawImage |
Draws an image with its top left corner at (x, y), blended by the alpha of its pixels. |
SetClip
Section titled “SetClip”void SetClip(Rect clip)Restricts drawing to a rectangle (within the image).
void Clear(Color color)Fills the whole image (ignoring the clip rectangle) with one color.
void Blend(int x, int y, Color color, int coverage)Blends one pixel: coverage 0 (nothing) to 255 (the color with its own alpha).
FillRect
Section titled “FillRect”void FillRect(Rect rect, Color color)Fills a rectangle.
StrokeRect
Section titled “StrokeRect”void StrokeRect(Rect rect, int width, Color color)Draws the outline of a rectangle, width pixels thick, inside the rectangle.
FillRoundRect
Section titled “FillRoundRect”void FillRoundRect(Rect rect, int radius, Color color)Fills a rectangle with rounded corners of the given radius (smooth edges).
StrokeRoundRect
Section titled “StrokeRoundRect”void StrokeRoundRect(Rect rect, int radius, int width, Color color)Draws the outline of a rounded rectangle, width pixels thick, inside the rectangle.
FillCircle
Section titled “FillCircle”void FillCircle(double cx, double cy, double radius, Color color)Fills a circle (smooth edge); the center may lie between pixels.
void Line(double x0, double y0, double x1, double y1, double width, Color color)Draws a line width pixels thick with round ends (smooth edges); coordinates may lie between pixels.
int Text(Font font, int x, int y, StringSlice text, Color color)Draws text with its top left corner at (x, y) and returns its width. Line ends are not interpreted.
DrawImage
Section titled “DrawImage”void DrawImage(Image image, int x, int y)Draws an image with its top left corner at (x, y), blended by the alpha of its pixels.