Sometimes you may wish to use GDI+ to draw on an ImageGlue Canvas. This allows you to take advantage of the sophisticated and comprehensive image manipulation available in ImageGlue and combine it with the powerful drawing commands available in GDI+.
1
Drawing our Image

We create our ImageGlue canvas and draw our image onto it.

[C#] Canvas canvas = new Canvas(Server.MapPath("rez/birds.jpg"));


[Visual Basic] Dim canvas As New Canvas(Server.MapPath("rez/birds.jpg"))


2
Drawing using GDI+

To draw on our canvas using GDI+ we'll need to wrap the Canvas in a GDI+ Graphics context. Note that while the Canvas is wrapped we won't be able to use any ImageGlue Canvas methods. We draw a circle and a pie using GDI+ drawing commands.

[C#] using (CanvasWrapper wrapper = new CanvasWrapper(canvas)) {
Pen pn = new Pen(Color.DarkGoldenrod, 8);
wrapper.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
wrapper.Graphics.DrawEllipse(pn, 10, 25, 125, 125);
pn.Color = Color.SteelBlue;
wrapper.Graphics.DrawPie(pn, 10, 25, 125, 125, 45, 120);
}


[Visual Basic] Using wrapper As New CanvasWrapper(canvas)
Dim pn As New Pen(Color.DarkGoldenrod, 8)
wrapper.Graphics.SmoothingMode = SmoothingMode.AntiAlias
wrapper.Graphics.DrawEllipse(pn, 10, 25, 125, 125)
pn.Color = Color.SteelBlue
wrapper.Graphics.DrawPie(pn, 10, 25, 125, 125, 45, _
120)
End Using


3
Saving

To export we use the Canvas SaveAs method.

[C#] canvas.SaveAs(Server.MapPath("GDI_Drawing_NET_8.jpg"));


[Visual Basic] canvas.SaveAs(Server.MapPath("GDI_Drawing_NET_8.jpg"))


4
Input and Output

Sample input and output images are shown below.


rez/birds.jpg


GDI_Drawing_NET_8.jpg