Search This Blog

Tuesday, November 27, 2012

Find Height and Width of image using C#

I know, there are some requirements in which we need to find out the image's height and width.
Either the image is on server or it's been uploaded using fileupload control in asp.net using C#.

Following is the example for finding the height and width of image which is being uploaded through FileUpload Control in asp.net.
My favourite language is C#, so this code is also written in C#.
Those who love VB, please use a code convertor.

lets say fileUpload control as fiUpload

protected void findHieghtWidht_Click(object sender, EventArgs e)
{
    string uploadImageType = fiUpload.PostedFile.ContentType.ToString().ToLower();
    stirng uploadImageName = fiUpload.PostedFile.FileName;
    System.Drawing.Image uploadImage = System.Drawing.Image.FromStream(fiUpload.PostedFile.InputStream);
    float imageWidth = uploadImage.PhysicalDimension.Width;
    float imageHeight = uploadImage.PhysicalDimension.Height;


 Same way you can load the image stored on server, and get the height and width.

344808_CrashPlan 10% Savings - 120x600 animated