Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET: get height and width of an image [duplicate]

Tags:

asp.net

image

Various flavours of this question have been asked but I haven't found a correct answer yet.

Say i have an .jpg image on the file server and that I need to get its height and width. How do I do it in asp.net?

I've seen a few answers which suggests to do something like this:

System.Drawing.Image image=System.Drawing.Image.FromFile(PicturePath); 
int ActualWidth=image.Width;
int ActualHeight=image.Height;
image.Dispose();

This would work fine except that classes within the System.Drawing namespace are not supported for use within an ASP.NET service.

So, how do you get the actual height and width of an image in ASP.net?

like image 343
Anthony Avatar asked Jan 06 '10 20:01

Anthony


1 Answers

add an server side image control on the aspx

<asp:image ID="img1" runat="server" src="" />

and on the code behind give it a src

img1.src = System.Drawing.Image.FromFile(PicturePath);

int ActualWidth = img1.Width;
int ActualHeight = img1.Height;
img1.src = "";
like image 126
Hiyasat Avatar answered Oct 06 '22 03:10

Hiyasat