Graphics Class
NuGet: GHIElectronics.TinyCLR.Drawing
Assembly: GHIElectronics.TinyCLR.Drawing
Namespace: System.Drawing
2-D drawing surface backed by a Bitmap. Issue line, rectangle, ellipse, text, and image draws against this surface, then push the result to the display via Flush(IntPtr).
public class Graphics : MarshalByRefObject, IDisposable
Properties
Width
public int Width { get; }
Gets the width of the drawing surface in pixels.
Height
public int Height { get; }
Gets the height of the drawing surface in pixels.
PageUnit
public GraphicsUnit PageUnit { get; }
Gets the unit of measure for this surface, which is always pixels.
Methods
GetPixel(int x, int y)
public uint GetPixel(int x, int y)
Gets the ARGB color of the pixel at the given coordinates.
Returns uint
SetPixel(int x, int y, Color color)
public void SetPixel(int x, int y, Color color)
Sets the color of the pixel at the given coordinates.
GetBitmap()
public byte[] GetBitmap()
Gets the raw pixel data of the drawing surface.
Returns byte[]
GetBitmap(int x, int y, int width, int height)
public byte[] GetBitmap(int x, int y, int width, int height)
Gets the raw pixel data for a rectangular region of the drawing surface.
Returns byte[]
Dispose()
public void Dispose()
Releases the resources used by this drawing surface.
MeasureString(string text, Font font)
public SizeF MeasureString(string text, Font font)
Measures the pixel size needed to render the given text in the given font.
Returns SizeF
MeasureString(string text, Font font, SizeF layoutArea, StringFormat stringFormat)
public SizeF MeasureString(string text, Font font, SizeF layoutArea, StringFormat stringFormat)
Measures the pixel size needed to render the given text within a layout area using the given format.
Returns SizeF
Clear()
public void Clear()
Clears the entire drawing surface to its default color.
FromHdc(IntPtr hdc)
public static Graphics FromHdc(IntPtr hdc)
Creates a drawing surface for the display referenced by the given device context handle.
Returns Graphics
FromImage(Image image)
public static Graphics FromImage(Image image)
Gets the drawing surface backing the given image.
Returns Graphics
Flush()
public void Flush()
Pushes the contents of the drawing surface to the display.
DrawImage(Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
public void DrawImage(Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
Draws a portion of an image at the specified location.
DrawImage(Image image, int x, int y, int width, int height)
public void DrawImage(Image image, int x, int y, int width, int height)
Draws an image at the specified location, scaled to the given size.
DrawImage(Image image, int x, int y)
public void DrawImage(Image image, int x, int y)
Draws an image at the specified location using its original size.
DrawImage(Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
public void DrawImage(Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
Draws a portion of an image into the destination rectangle, scaling as needed.
DrawLine(Pen pen, int x1, int y1, int x2, int y2)
public void DrawLine(Pen pen, int x1, int y1, int x2, int y2)
Draws a line between two points using the given pen.
DrawString(string s, Font font, Brush brush, float x, float y)
public void DrawString(string s, Font font, Brush brush, float x, float y)
Draws text at the given location using the specified font and brush.
DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle)
public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle)
Draws text wrapped within the given layout rectangle.
DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
Draws text within the given layout rectangle using the specified format.
DrawEllipse(Pen pen, int x, int y, int width, int height)
public void DrawEllipse(Pen pen, int x, int y, int width, int height)
Draws the outline of an ellipse bounded by the given rectangle using the specified pen.
DrawRectangle(Pen pen, int x, int y, int width, int height)
public void DrawRectangle(Pen pen, int x, int y, int width, int height)
Draws the outline of a rectangle using the specified pen.
FillEllipse(Brush brush, int x, int y, int width, int height)
public void FillEllipse(Brush brush, int x, int y, int width, int height)
Fills the interior of an ellipse bounded by the given rectangle using the specified brush.
FillRectangle(Brush brush, int x, int y, int width, int height)
public void FillRectangle(Brush brush, int x, int y, int width, int height)
Fills the interior of a rectangle using the specified brush.
DrawImage(int xDst, int yDst, Image image, int xSrc, int ySrc, int width, int height, ushort opacity)
public void DrawImage(int xDst, int yDst, Image image, int xSrc, int ySrc, int width, int height, ushort opacity)
Draws a region of an image at the destination location with the given opacity.
Flush(int x, int y, int width, int height)
public void Flush(int x, int y, int width, int height)
Pushes a rectangular region of the drawing surface to the display.
SetClippingRectangle(int x, int y, int width, int height)
public void SetClippingRectangle(int x, int y, int width, int height)
Restricts drawing to the given rectangular region.
DrawTextInRect(string text, int x, int y, int width, int height, DrawTextAlignment dtFlags, Color color, Font font)
public void DrawTextInRect(string text, int x, int y, int width, int height, DrawTextAlignment dtFlags, Color color, Font font)
Draws text within the given rectangle using the specified alignment flags.
DrawTextInRect(ref string text, ref int xRelStart, ref int yRelStart, int x, int y, int width, int height, DrawTextAlignment dtFlags, Color color, Font font)
public bool DrawTextInRect(ref string text, ref int xRelStart, ref int yRelStart, int x, int y, int width, int height, DrawTextAlignment dtFlags, Color color, Font font)
Draws text within the given rectangle, updating the relative start position, and returns whether more text remains.
Returns bool
RotateImage(int angle, int xDst, int yDst, Image image, int xSrc, int ySrc, int width, int height, ushort opacity)
public void RotateImage(int angle, int xDst, int yDst, Image image, int xSrc, int ySrc, int width, int height, ushort opacity)
Draws a region of an image rotated by the given angle at the destination location.
MakeTransparent(Color color)
public void MakeTransparent(Color color)
Makes the given color transparent on the drawing surface.
StretchImage(int xDst, int yDst, int widthDst, int heightDst, Image image, int xSrc, int ySrc, int widthSrc, int heightSrc, ushort opacity)
public void StretchImage(int xDst, int yDst, int widthDst, int heightDst, Image image, int xSrc, int ySrc, int widthSrc, int heightSrc, ushort opacity)
Draws a region of an image scaled to fill the destination rectangle.
TileImage(int xDst, int yDst, Image image, int width, int height, ushort opacity)
public void TileImage(int xDst, int yDst, Image image, int width, int height, ushort opacity)
Tiles an image to fill the given area at the destination location.
Scale9Image(int xDst, int yDst, int widthDst, int heightDst, Image image, int leftBorder, int topBorder, int rightBorder, int bottomBorder, ushort opacity)
public void Scale9Image(int xDst, int yDst, int widthDst, int heightDst, Image image, int leftBorder, int topBorder, int rightBorder, int bottomBorder, ushort opacity)
Draws an image using nine-slice scaling so its borders are not stretched.
Events
OnFlushEvent
static public event OnFlushHandler OnFlushEvent
Occurs when the drawing surface is flushed.