Thursday, 28 February 2013

Rotate An Image


.ASPX CODE:

<asp:Image ID="Image1" runat="server" Height="297px"
ImageUrl="~/images/image.bmp" Width="343px" />

<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Rotate Image" />

.CS CODE:

protected void Button1_Click(object sender, EventArgs e)
{
// get the full path of image url
string path = Server.MapPath(Image1.ImageUrl);

// creating image from the image url
System.Drawing.Image i = System.Drawing.Image.FromFile(path);

// rotate Image 90' Degree
i.RotateFlip(RotateFlipType.Rotate90FlipXY);

// save it to its actual path
i.Save(path);

// release Image File
i.Dispose();

// Set Image Control Attribute property to new image(but its old path)
Image1.Attributes.Add("ImageUrl", path);
}

No comments:

Post a Comment