This example shows how to enumerate through a set of files creating thumbnail images from the originals.
Creating the Canvas

We will need a canvas so we create it here.

[C#] Canvas canvas = new Canvas();

[Visual Basic] Dim canvas As New Canvas()

Creating the image

We create an image and then limit its height to be less than or equal to 120 pixels. If the original height of the image is less than 120 pixels, the original size of the image will be used, otherwise the width will be calculated based on a height of 120 pixels and the aspect ratio of the original image.

Also note that we could substitute Size(0, 120) with Size(120, 0) to limit the width instead of the height.

[C#] XImage image = XImage.FromFile(Server.MapPath("rez/pic.jpg"));
DrawOptions drawOpts = new DrawOptions();
drawOpts.Limit = new Size(0, 120);

[Visual Basic] Dim image As XImage = XImage.FromFile(Server.MapPath("rez/pic.jpg"))
Dim drawOpts As New DrawOptions()
drawOpts.Limit = New Size(0, 120)


We draw the image on the Canvas.

[C#] canvas.DrawImage(image, drawOpts);

[Visual Basic] canvas.DrawImage(image, drawOpts)


Finally we save the picture as a JPEG image.

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

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

Input and Output

Sample input and output images are shown below.