Export the Canvas to a System.Drawing Bitmap.
Syntax

[C#]

Bitmap ToBitmap();
Bitmap ToBitmap(string inType);

[Visual Basic]

Function ToBitmap() As Bitmap
Function ToBitmap(inType As String) As Bitmap
Params
Name Description
inType An intermediate type specified by file extension.
return The System.Drawing Bitmap.
Notes

This method will create an RGB System.Drawing Bitmap from a Canvas. The two different versions of the function work a slightly different way.

The parameterless function rasterizes the Canvas directly into a new Bitmap, preserving transparency where appropriate.

The version taking a type, works via an intermediate file format which means that export settings affect the output. The UseAlpha property determines if alpha transparency is preserved in the output Bitmap. The HRes and VRes properties determine the resolution of the output.

See Also

FromBitmap

Example

Here we create a canvas and draw a JPEG file into it. We then copy the Canvas into a Bitmap and export it as a GIF using GDI+.

[C#]Canvas canvas = new Canvas(Server.MapPath("rez/cartoon.jpg"));
Bitmap bitmap = canvas.ToBitmap();
bitmap.Save(Server.MapPath("cartoon.gif"), ImageFormat.Gif);


[Visual Basic]Dim canvas As New Canvas(Server.MapPath("rez/cartoon.jpg"))
Dim bitmap As Bitmap = canvas.ToBitmap()
bitmap.Save(Server.MapPath("cartoon.gif"), ImageFormat.Gif)