Get File Size in KB, Dimensions (Height and Width) of Uploaded Image in ASP.Net in C#
In this article, we learn how to get size, height and width of uploaded image in asp.net in c#. As you have learned Imagecompression without losing quality in asp.net c# but If we want to compress image after specific size and height or width. We can do this very easily using both articles.
Source
Code:
<fieldset style="width:350px">
<legend>Get
File Size,Height and Width of Uploaded Image </legend>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br /> <br />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="btnUpload_Click" />
</fieldset>
Code
Behind:
protected void
btnUpload_Click(object sender, EventArgs e)
{
System.Drawing.Image img =
System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
int
height = img.Height;
int width
= img.Width;
decimal
size = Math.Round(((decimal)FileUpload1.PostedFile.ContentLength / (decimal)1024),
2);
ClientScript.RegisterClientScriptBlock(this.GetType(),
"alert", "alert('Size:
" + size + "KB\\nHeight: " + height + "\\nWidth:
" + width + "');", true);
}
Out-put:
![Get File Size in KB, Dimensions (Height and Width) of Uploaded Image in ASP.Net in C#](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyV93Ze1HV3SImH86JchsEWzvCi-uCYHmTKssKUQvT65NFzVkFJdoNMpTpo0EOEmw4eYVbSnsIYTnCgGU0ANhy0qFgGzly_Jm8jEYFMwFnXbZC4Adq4BzyqlMQLJc1QaTsTmvM1wa4vSun65itk8aT_DrLnrLezeTFd4zNORgEgzmGlj2p3FpJpdsa/s72-w640-c-h298/Get%20File%20Size%20in%20KB,%20Dimensions%20(Height%20and%20Width)%20of%20Uploaded%20Image%20in%20ASP.Net%20in%20C%23.gif)
No comments: