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?
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 = "";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With