This example shows how to draw an image from a file, rotated 90 degrees clockwise.
1
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()


2
Drawing the Image

Draw the image rotated 90 degrees. Because we rotate around the origin we will lose the image off the edge of our canvas unless we translate the image back onto the canvas.

[C#] XImage image = XImage.FromFile(Server.MapPath("rez/birds.jpg"));
DrawOptions drawOpts = new DrawOptions(canvas);
drawOpts.Transform.Rotate(90);
drawOpts.Transform.Translate(image.Height, 0);
canvas.DrawImage(image, drawOpts);


[Visual Basic] Dim image As XImage = XImage.FromFile(Server.MapPath("rez/birds.jpg"))
Dim drawOpts As New DrawOptions(canvas)
drawOpts.Transform.Rotate(90)
drawOpts.Transform.Translate(image.Height, 0)
canvas.DrawImage(image, drawOpts)


3
Saving

Finally we save the picture as a medium quality JPEG image.

[C#] canvas.Export.Quality = 50;
canvas.SaveAs(Server.MapPath("Rotating_an_Image_3.jpg"));


[Visual Basic] canvas.Export.Quality = 50
canvas.SaveAs(Server.MapPath("Rotating_an_Image_3.jpg"))


4
Input and Output

Sample input and output images are shown below.


birds.jpg


Rotating_an_Image_3.jpg