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
DrawingContext(Bitmap)
Creates a drawing context for the specified bitmap.
public DrawingContext(Bitmap bmp)
Parameters
bmp
BitmapThe bitmap.
Properties
Bitmap
Gets the bitmap associated with this drawing context.
public Bitmap Bitmap { get; }
Property Value
Height
Gets the height of the bitmap.
public int Height { get; }
Property Value
Width
Gets the width of the bitmap.
public int Width { get; }
Property Value
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
BitmapThe source image to blend onto the current bitmap.
destinationX
intThe x-coordinate of the upper-left corner of the destination rectangle.
destinationY
intThe y-coordinate of the upper-left corner of the destination rectangle.
sourceX
intThe x-coordinate of the upper-left corner of the source rectangle.
sourceY
intThe y-coordinate of the upper-left corner of the source rectangle.
sourceWidth
intThe width of the source rectangle.
sourceHeight
intThe height of the source rectangle.
opacity
ushortThe 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
boolTrue 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
BrushThe brush to fill the ellipse with.
pen
PenThe pen used to draw the outline of the ellipse.
x
intThe x-coordinate of the upper-left corner of the ellipse.
y
intThe y-coordinate of the upper-left corner of the ellipse.
xRadius
intThe x-radius of the ellipse.
yRadius
intThe 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
BitmapThe bitmap to draw.
x
intThe x-coordinate of the upper-left corner of the image.
y
intThe 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
BitmapThe bitmap to draw a portion of.
destinationX
intThe x-coordinate of the upper-left corner of the destination rectangle.
destinationY
intThe y-coordinate of the upper-left corner of the destination rectangle.
sourceX
intThe x-coordinate of the upper-left corner of the source rectangle.
sourceY
intThe y-coordinate of the upper-left corner of the source rectangle.
sourceWidth
intThe width of the source rectangle.
sourceHeight
intThe 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
PenThe pen to use to draw the line.
x0
intThe x-coordinate of the start point of the line.
y0
intThe y-coordinate of the start point of the line.
x1
intThe x-coordinate of the end point of the line.
y1
intThe 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
BrushThe brush to use to fill the polygon.
pen
PenThe 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
BrushThe brush to use for filling the rectangle.
pen
PenThe pen to use for outlining the rectangle.
x
intThe x-coordinate of the top-left corner of the rectangle.
y
intThe y-coordinate of the top-left corner of the rectangle.
width
intThe width of the rectangle.
height
intThe 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
stringThe text string to draw.
font
FontThe font used to draw the text.
color
ColorThe color used to draw the text.
x
intThe x-coordinate of the upper-left corner of the text string.
y
intThe 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
stringThe text string to draw.
font
FontThe font used to draw the text.
color
ColorThe color used to draw the text.
x
intThe x-coordinate of the upper-left corner of the text string.
y
intThe y-coordinate of the upper-left corner of the text string.
width
intThe width of the text string.
height
intThe height of the text string.
alignment
TextAlignmentThe horizontal alignment of the text within the bounding rectangle.
trimming
TextTrimmingThe 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
intThe x-coordinate of the clipping rectangle.
y
intThe y-coordinate of the clipping rectangle.
width
intThe width of the clipping rectangle.
height
intThe 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
intReceives the x component of the translation.
y
intReceives 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
intThe x-coordinate of the clipping rectangle.
y
intThe y-coordinate of the clipping rectangle.
width
intThe width of the clipping rectangle.
height
intThe 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
intThe angle to rotate the source image, in degrees.
destinationX
intThe x-coordinate of the upper-left corner of the destination rectangle.
destinationY
intThe y-coordinate of the upper-left corner of the destination rectangle.
bitmap
BitmapThe source image to rotate and blend onto the current bitmap.
sourceX
intThe x-coordinate of the upper-left corner of the source rectangle.
sourceY
intThe y-coordinate of the upper-left corner of the source rectangle.
sourceWidth
intThe width of the source rectangle.
sourceHeight
intThe height of the source rectangle.
opacity
ushortThe 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
intThe x-coordinate of the upper-left corner of the destination rectangle.
yDst
intThe y-coordinate of the upper-left corner of the destination rectangle.
widthDst
intThe width of the destination rectangle.
heightDst
intThe height of the destination rectangle.
bitmap
BitmapThe source bitmap to draw.
leftBorder
intThe width of the left border.
topBorder
intThe height of the top border.
rightBorder
intThe width of the right border.
bottomBorder
intThe height of the bottom border.
opacity
ushortThe 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
ColorThe color to set the pixel to.
x
intThe x-coordinate of the pixel.
y
intThe 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
intThe x-coordinate of the upper-left corner of the destination rectangle.
yDst
intThe y-coordinate of the upper-left corner of the destination rectangle.
widthDst
intThe width of the destination rectangle.
heightDst
intThe height of the destination rectangle.
bitmap
BitmapThe source bitmap to draw.
xSrc
intThe x-coordinate of the upper-left corner of the portion of the source bitmap to draw.
ySrc
intThe y-coordinate of the upper-left corner of the portion of the source bitmap to draw.
widthSrc
intThe width of the portion of the source bitmap to draw.
heightSrc
intThe height of the portion of the source bitmap to draw.
opacity
ushortThe 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
intThe x-coordinate of the upper-left corner of the destination rectangle.
yDst
intThe y-coordinate of the upper-left corner of the destination rectangle.
bitmap
BitmapThe source bitmap to tile.
width
intThe width of the destination rectangle.
height
intThe height of the destination rectangle.
opacity
ushortThe 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)