Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using asp.net 3.5 and c# on my web site. Here is my question:

I have an upload button and asp:Image on a page. An user can upload an image from his computer and that image will be displayed in the asp:image. But before I display the image, I would like to check the width and height of the uploaded image. How do I do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
178 views
Welcome To Ask or Share your Answers For Others

1 Answer

    Image img = System.Drawing.Image.FromFile("test.jpg");
    int width = img.Width;
    int height = img.Height;

You may need to add the System.Drawing reference.

You may also use the FromStream function if you have not saved the image to disk yet, but looking at how you're using the image (viewable by user in an Image control), I suspect it's already on disk. Stream to image may or may not be faster than disk to image. You might want to do some profiling to see which has better performance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...