---
title: "Drawing Shapes"
canonical: https://www.graphicsmill.com/docs/gm5/DrawingShapes.htm
product: "Graphics Mill 5.5 for .NET"
---

This documentation is for the old version. [Go to the latest Graphics Mill docs](https://www.graphicsmill.com/docs/gm/)

# Drawing Shapes
 
At this article we will see a code example how to draw shapes in Graphics Mill for .NET.
 
Drawing functionality of the Graphics Mill for .NET is presented by [GdiGraphics](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Drawing_GdiGraphics.htm.md) class. You can draw outline and shape fill separately. The following shapes are supported:
 
- Rectangle. You just specify top left corner position and rectangle width and height. Outline is drawn with [DrawRectangle](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawRectangle.htm.md), fill is drawn with [FillRectangle](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_FillRectangle.htm.md).
- Ellipse. You specify tightest bounding rectangle for the ellipse. Outline is drawn with [DrawEllipse](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawEllipse.htm.md), fill is drawn with [FillEllipse](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_FillEllipse.htm.md).
- Pie. You specify the ellipse and a sector to cut. Outline is drawn with [DrawPie](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawPie.htm.md), fill is drawn with [FillPie](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_FillPie.htm.md).
- Polygon. You specify an array of polygon vertices. Outline is drawin with [DrawPolygon](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_DrawPolygon.htm.md), fill is drawn with [FillPolygon](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Drawing_GdiGraphics_FillPolygon.htm.md).

The appearance of the outline of the shapes is managed by special object called *pen*. The filling of the shapes can be specified by the *brush*. You can read about it more detailed at the [Pens and Brushes](https://www.graphicsmill.com/docs/gm5/PensandBrushes.htm.md) article.
 
The code below demonstrates the usage of these methods. This figure demonstrates output of this code.
 ![GDI graphics](https://www.graphicsmill.com/docs/gm5/DrawShapesGdi.gif) 
```
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
 Aurigma.GraphicsMill.RgbColor.White, 185, 145, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

Dim graphics As Aurigma.GraphicsMill.Drawing.GdiGraphics = bitmap.GetGdiGraphics()

'Draw filled and outlined rectangle
Dim pen As New Aurigma.GraphicsMill.Drawing.Pen(Aurigma.GraphicsMill.RgbColor.Red, 3)
Dim brush As New Aurigma.GraphicsMill.Drawing.SolidBrush( _
 Aurigma.GraphicsMill.RgbColor.FromRgb(&HDD, &HDD, &HFF))
graphics.FillRectangle(brush, 10, 10, 100, 60)
graphics.DrawRectangle(pen, 10, 10, 100, 60)

'Draw filled but non-outlined ellipse
brush.Color = Aurigma.GraphicsMill.RgbColor.Yellow
graphics.FillEllipse(brush, 60, 40, 100, 80)

'Draw outlined but non-filled polygon 
pen.Color = Aurigma.GraphicsMill.RgbColor.Green
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
pen.Width = 1
Dim points As System.Drawing.Point() = { _
 New System.Drawing.Point(20, 30), New System.Drawing.Point(50, 2), _
 New System.Drawing.Point(180, 30), New System.Drawing.Point(80, 140)}
graphics.DrawPolygon(pen, points)
```
 
```csharp
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(
    Aurigma.GraphicsMill.RgbColor.White, 185, 145, 
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

//Draw filled and outlined rectangle
Aurigma.GraphicsMill.Drawing.Pen pen = new Aurigma.GraphicsMill.Drawing.Pen(
    Aurigma.GraphicsMill.RgbColor.Red, 3);
Aurigma.GraphicsMill.Drawing.SolidBrush brush = new Aurigma.GraphicsMill.Drawing.SolidBrush( 
    Aurigma.GraphicsMill.RgbColor.FromRgb(0xDD, 0xDD, 0xFF));
graphics.FillRectangle(brush, 10, 10, 100, 60);
graphics.DrawRectangle(pen, 10, 10, 100, 60);

//Draw filled but non-outlined ellipse
brush.Color = Aurigma.GraphicsMill.RgbColor.Yellow;
graphics.FillEllipse(brush, 60, 40, 100, 80);

//Draw outlined but non-filled polygon 
pen.Color = Aurigma.GraphicsMill.RgbColor.Green;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
pen.Width = 2;
System.Drawing.Point[] points = { 
    new System.Drawing.Point(20, 30), new System.Drawing.Point(50, 2), 
    new System.Drawing.Point(180, 30), new System.Drawing.Point(80, 140)};
graphics.DrawPolygon(pen, points);
```
 
Draw attention, these method are working in the same way as appropriate methods of the System.Drawing.Graphics class. The code example for System.Drawing.Graphics usage can be found below. However before you use it, we would recommend reading an article [Comparison: GdiGraphics and System.Drawing.Graphics](https://www.graphicsmill.com/docs/gm5/ComparisonGdiGraphicsandSystemDrawingGraphics.htm.md).
 
The output of this code is adduced here:
 ![GDI+ graphics](https://www.graphicsmill.com/docs/gm5/DrawShapes.png) 
```
Dim bitmap As New Aurigma.GraphicsMill.Bitmap( _
 Aurigma.GraphicsMill.RgbColor.White, 185, 145, _
 Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)

Dim graphics As System.Drawing.Graphics = bitmap.GetGdiplusGraphics()

graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias

'Draw filled and outlined rectangle
Dim pen As New System.Drawing.Pen(System.Drawing.Color.Red, 3)
Dim brush As New System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(&HFFDDDDFF))
graphics.FillRectangle(brush, 10, 10, 100, 60)
graphics.DrawRectangle(pen, 10, 10, 100, 60)

'Draw filled but non-outlined ellipse
brush.Color = System.Drawing.Color.FromArgb(200, System.Drawing.Color.Yellow)
graphics.FillEllipse(brush, 60, 40, 100, 80)

'Draw outlined but non-filled polygon 
pen.Color = System.Drawing.Color.FromArgb(150, System.Drawing.Color.Green)
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
pen.Width = 2
Dim points As System.Drawing.Point() = { _
 New System.Drawing.Point(20, 30), New System.Drawing.Point(50, 2), _
 New System.Drawing.Point(180, 30), New System.Drawing.Point(80, 140)}
graphics.DrawPolygon(pen, points)
```
 
```csharp
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(
    Aurigma.GraphicsMill.RgbColor.White, 185, 145, 
    Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

System.Drawing.Graphics graphics = bitmap.GetGdiplusGraphics();

graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

//Draw filled and outlined rectangle
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 3);
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(
    System.Drawing.Color.FromArgb(0xFF, 0xDD, 0xDD, 0xFF));
graphics.FillRectangle(brush, 10, 10, 100, 60);
graphics.DrawRectangle(pen, 10, 10, 100, 60);

//Draw filled but non-outlined ellipse
brush.Color = System.Drawing.Color.FromArgb(200, System.Drawing.Color.Yellow);
graphics.FillEllipse(brush, 60, 40, 100, 80);

//Draw outlined but non-filled polygon 
pen.Color = System.Drawing.Color.FromArgb(150, System.Drawing.Color.Green);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
pen.Width = 2;
System.Drawing.Point[] points = { 
    new System.Drawing.Point(20, 30), new System.Drawing.Point(50, 2), 
    new System.Drawing.Point(180, 30), new System.Drawing.Point(80, 140)};
graphics.DrawPolygon(pen, points);
```
