Table of Contents

Class DrawingContext

Namespace
nanoFramework.Presentation.Media
Assembly
nanoFramework.Graphics.dll

Drawing Context.

public class DrawingContext : DispatcherObject, IDisposable
Inheritance
DrawingContext
Implements
Inherited Members
Extension Methods

Constructors

DrawingContext(int, int)

Creates a drawing context for an empty bitmap of a specific width and height.

public DrawingContext(int width, int height)

Parameters

width int

The target width of the bitmap.

height int

The target height of the bitmap.

DrawingContext(Bitmap)

Creates a drawing context for the specified bitmap.

public DrawingContext(Bitmap bmp)

Parameters

bmp Bitmap

The bitmap.

Properties

Bitmap

Gets the bitmap associated with this drawing context.

public Bitmap Bitmap { get; }

Property Value

Bitmap

Height

Gets the height of the bitmap.

public int Height { get; }

Property Value

int

Width

Gets the width of the bitmap.

public int Width { get; }

Property Value

int

Methods

BlendImage(Bitmap, int, int, int, int, int, int, ushort)

Blends the specified source image onto the current bitmap at the specified location.

public void BlendImage(Bitmap source, int destinationX, int destinationY, int sourceX, int sourceY, int sourceWidth, int sourceHeight, ushort opacity)

Parameters

source Bitmap

The source image to blend onto the current bitmap.

destinationX int

The x-coordinate of the upper-left corner of the destination rectangle.

destinationY int

The y-coordinate of the upper-left corner of the destination rectangle.

sourceX int

The x-coordinate of the upper-left corner of the source rectangle.

sourceY int

The y-coordinate of the upper-left corner of the source rectangle.

sourceWidth int

The width of the source rectangle.

sourceHeight int

The height of the source rectangle.

opacity ushort

The opacity of the blended image, where 0 is completely transparent and 256 is completely opaque.

Clear()

Clears the bitmap associated with this drawing context.

public void Clear()

Dispose()

Disposes of the bitmap and frees up any resources used by the object.

public void Dispose()

Dispose(bool)

Disposes of the bitmap and frees up any resources used by the object.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

True for disposing.

DrawEllipse(Brush, Pen, int, int, int, int)

Draws an ellipse on the bitmap with the specified brush, pen, location, and radii.

public void DrawEllipse(Brush brush, Pen pen, int x, int y, int xRadius, int yRadius)

Parameters

brush Brush

The brush to fill the ellipse with.

pen Pen

The pen used to draw the outline of the ellipse.

x int

The x-coordinate of the upper-left corner of the ellipse.

y int

The y-coordinate of the upper-left corner of the ellipse.

xRadius int

The x-radius of the ellipse.

yRadius int

The y-radius of the ellipse.

DrawImage(Bitmap, int, int)

Draws an image on the bitmap at the specified location.

public void DrawImage(Bitmap source, int x, int y)

Parameters

source Bitmap

The bitmap to draw.

x int

The x-coordinate of the upper-left corner of the image.

y int

The y-coordinate of the upper-left corner of the image.

DrawImage(Bitmap, int, int, int, int, int, int)

Draws a portion of the specified image on the bitmap at the specified location and with the specified size.

public void DrawImage(Bitmap source, int destinationX, int destinationY, int sourceX, int sourceY, int sourceWidth, int sourceHeight)

Parameters

source Bitmap

The bitmap to draw a portion of.

destinationX int

The x-coordinate of the upper-left corner of the destination rectangle.

destinationY int

The y-coordinate of the upper-left corner of the destination rectangle.

sourceX int

The x-coordinate of the upper-left corner of the source rectangle.

sourceY int

The y-coordinate of the upper-left corner of the source rectangle.

sourceWidth int

The width of the source rectangle.

sourceHeight int

The height of the source rectangle.

DrawLine(Pen, int, int, int, int)

Draws a line with the specified pen between the specified points.

public void DrawLine(Pen pen, int x0, int y0, int x1, int y1)

Parameters

pen Pen

The pen to use to draw the line.

x0 int

The x-coordinate of the start point of the line.

y0 int

The y-coordinate of the start point of the line.

x1 int

The x-coordinate of the end point of the line.

y1 int

The y-coordinate of the end point of the line.

DrawPolygon(Brush, Pen, int[])

Draws a polygon with the specified brush and pen.

public void DrawPolygon(Brush brush, Pen pen, int[] pts)

Parameters

brush Brush

The brush to use to fill the polygon.

pen Pen

The pen to use to draw the polygon edges.

pts int[]

The points that define the vertices of the polygon.

DrawRectangle(Brush, Pen, int, int, int, int)

Draws a rectangle onto the bitmap using the specified brush and pen.

public void DrawRectangle(Brush brush, Pen pen, int x, int y, int width, int height)

Parameters

brush Brush

The brush to use for filling the rectangle.

pen Pen

The pen to use for outlining the rectangle.

x int

The x-coordinate of the top-left corner of the rectangle.

y int

The y-coordinate of the top-left corner of the rectangle.

width int

The width of the rectangle.

height int

The height of the rectangle.

DrawText(string, Font, Color, int, int)

Draws a text string with the specified font and color at the specified position.

public void DrawText(string text, Font font, Color color, int x, int y)

Parameters

text string

The text string to draw.

font Font

The font used to draw the text.

color Color

The color used to draw the text.

x int

The x-coordinate of the upper-left corner of the text string.

y int

The y-coordinate of the upper-left corner of the text string.

DrawText(ref string, Font, Color, int, int, int, int, TextAlignment, TextTrimming)

Draws a text string with the specified font, color, width, and height at the specified position.

public bool DrawText(ref string text, Font font, Color color, int x, int y, int width, int height, TextAlignment alignment, TextTrimming trimming)

Parameters

text string

The text string to draw.

font Font

The font used to draw the text.

color Color

The color used to draw the text.

x int

The x-coordinate of the upper-left corner of the text string.

y int

The y-coordinate of the upper-left corner of the text string.

width int

The width of the text string.

height int

The height of the text string.

alignment TextAlignment

The horizontal alignment of the text within the bounding rectangle.

trimming TextTrimming

The text trimming style to be applied to the text string.

Returns

bool

True if the text string was drawn successfully; otherwise, false.

GetClippingRectangle(out int, out int, out int, out int)

Gets the clipping rectangle for the current context.

public void GetClippingRectangle(out int x, out int y, out int width, out int height)

Parameters

x int

The x-coordinate of the clipping rectangle.

y int

The y-coordinate of the clipping rectangle.

width int

The width of the clipping rectangle.

height int

The height of the clipping rectangle.

GetTranslation(out int, out int)

Retrieves the current translation of the drawing context.

public void GetTranslation(out int x, out int y)

Parameters

x int

Receives the x component of the translation.

y int

Receives the y component of the translation.

PopClippingRectangle()

Pops the top clipping rectangle from the stack.

public void PopClippingRectangle()

PushClippingRectangle(int, int, int, int)

Pushes a new clipping rectangle onto the stack.

public void PushClippingRectangle(int x, int y, int width, int height)

Parameters

x int

The x-coordinate of the clipping rectangle.

y int

The y-coordinate of the clipping rectangle.

width int

The width of the clipping rectangle.

height int

The height of the clipping rectangle.

RotateImage(int, int, int, Bitmap, int, int, int, int, ushort)

Rotates the specified source image by the specified angle and blends it onto the current bitmap at the specified location.

public void RotateImage(int angle, int destinationX, int destinationY, Bitmap bitmap, int sourceX, int sourceY, int sourceWidth, int sourceHeight, ushort opacity)

Parameters

angle int

The angle to rotate the source image, in degrees.

destinationX int

The x-coordinate of the upper-left corner of the destination rectangle.

destinationY int

The y-coordinate of the upper-left corner of the destination rectangle.

bitmap Bitmap

The source image to rotate and blend onto the current bitmap.

sourceX int

The x-coordinate of the upper-left corner of the source rectangle.

sourceY int

The y-coordinate of the upper-left corner of the source rectangle.

sourceWidth int

The width of the source rectangle.

sourceHeight int

The height of the source rectangle.

opacity ushort

The opacity of the blended image, where 0 is completely transparent and 256 is completely opaque.

Scale9Image(int, int, int, int, Bitmap, int, int, int, int, ushort)

Draws a scalable nine-patch image on the display, scaling the middle section to fit the specified rectangle.

public void Scale9Image(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int leftBorder, int topBorder, int rightBorder, int bottomBorder, ushort opacity)

Parameters

xDst int

The x-coordinate of the upper-left corner of the destination rectangle.

yDst int

The y-coordinate of the upper-left corner of the destination rectangle.

widthDst int

The width of the destination rectangle.

heightDst int

The height of the destination rectangle.

bitmap Bitmap

The source bitmap to draw.

leftBorder int

The width of the left border.

topBorder int

The height of the top border.

rightBorder int

The width of the right border.

bottomBorder int

The height of the bottom border.

opacity ushort

The opacity of the image to draw, where 0 is fully transparent and 256 is fully opaque.

SetPixel(Color, int, int)

Sets the pixel at the specified coordinates to the specified color.

public void SetPixel(Color color, int x, int y)

Parameters

color Color

The color to set the pixel to.

x int

The x-coordinate of the pixel.

y int

The y-coordinate of the pixel.

StretchImage(int, int, int, int, Bitmap, int, int, int, int, ushort)

Draws an image on the display, stretching it to fit the specified destination rectangle.

public void StretchImage(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int xSrc, int ySrc, int widthSrc, int heightSrc, ushort opacity)

Parameters

xDst int

The x-coordinate of the upper-left corner of the destination rectangle.

yDst int

The y-coordinate of the upper-left corner of the destination rectangle.

widthDst int

The width of the destination rectangle.

heightDst int

The height of the destination rectangle.

bitmap Bitmap

The source bitmap to draw.

xSrc int

The x-coordinate of the upper-left corner of the portion of the source bitmap to draw.

ySrc int

The y-coordinate of the upper-left corner of the portion of the source bitmap to draw.

widthSrc int

The width of the portion of the source bitmap to draw.

heightSrc int

The height of the portion of the source bitmap to draw.

opacity ushort

The opacity of the image to draw, where 0 is fully transparent and 256 is fully opaque.

TileImage(int, int, Bitmap, int, int, ushort)

Draws an image repeatedly on the display, tiling it to fill the specified rectangle.

public void TileImage(int xDst, int yDst, Bitmap bitmap, int width, int height, ushort opacity)

Parameters

xDst int

The x-coordinate of the upper-left corner of the destination rectangle.

yDst int

The y-coordinate of the upper-left corner of the destination rectangle.

bitmap Bitmap

The source bitmap to tile.

width int

The width of the destination rectangle.

height int

The height of the destination rectangle.

opacity ushort

The opacity of the image to draw, where 0 is fully transparent and 256 is fully opaque.

Translate(int, int)

Translates the drawing context by a specified amount.

public void Translate(int dx, int dy)

Parameters

dx int

The amount to translate in the x direction.

dy int

The amount to translate in the y direction.