This example shows how to draw an image from a file, rotated 90 degrees clockwise.

 

   
1
 
Setting Up    
     

We start by setting up variables we will use later - the path to the source file and the path to the output file.

[Visual Basic]
Dim inpath, outpath As String
inpath = Server.MapPath("rez/birds.jpg")
outpath = Server.MapPath("rotatedbirds.jpg")

[C#]
string inpath = Server.MapPath("rez/birds.jpg");
string outpath = Server.MapPath("rotatedbirds.jpg");

 

   
2
 
Creating the Objects    
     

We will need a canvas so we create it here.

[Visual Basic]
Dim canvas As New Canvas

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

 

   
3
 
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 are careful. We could translate the image back onto the canvas but to do this we would need to know the size of the image. The easiest thing to do is to pin the top left of the bounds of the rotated image to the origin.

[Visual Basic]
canvas.DrawFile(inpath, "rotate=90 pin=0,0")

[C#]
canvas.DrawFile(inpath, "rotate=90 pin=0,0");

 

   
4
 
Saving    
     

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

[Visual Basic]
canvas.SaveAs(outpath , "Quality=medium")

[C#]
canvas.SaveAs(outpath , "Quality=medium");

 

   
5
 
Input and Output    
     

Sample input and output images are shown below.

birds.jpg

rotatedbirds.jpg