Answered by:
Best way to get the height and width of uploaded photos in ASP.NET?

Question
-
User1940910349 posted
I need the height and width in pixels. I am using the FileUplaod control in ASP.NET 2.0. How do I get the height and width in pixels?Thursday, February 26, 2009 1:04 AM
Answers
-
User-2064897223 posted
Load image into a Image object (System.Drawing.Image) and get width, height
Image image = Image.FromStream(file.InputSteam);
int height = image.Height;
int width = image.Width;
image.Dispose();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 26, 2009 1:43 AM -
User-2064897223 posted
File.InputStream is the stream of the file you need width and height.
You can also use System.Drawing.Image image = System.Drawing.Image.FromFile("filename") instead of InputStream
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 26, 2009 2:08 AM -
User-2064897223 posted
you are welcome. yes that make ambitious reference with Image web control and drawing.image. So best way is to yse System.Drawing.Image- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 26, 2009 2:43 AM
All replies
-
User-2064897223 posted
Load image into a Image object (System.Drawing.Image) and get width, height
Image image = Image.FromStream(file.InputSteam);
int height = image.Height;
int width = image.Width;
image.Dispose();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 26, 2009 1:43 AM -
User1940910349 posted
cool, thanks ashrafur,
ill come back and mark you as correct answer if it works
Thursday, February 26, 2009 1:47 AM -
User1940910349 posted
okay, dumb question,
what do you mean by (File.InputSteam)? it doesn't work if I type exactly that in. do i have to create an InputStream object?
Thursday, February 26, 2009 1:54 AM -
User-2064897223 posted
File.InputStream is the stream of the file you need width and height.
You can also use System.Drawing.Image image = System.Drawing.Image.FromFile("filename") instead of InputStream
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 26, 2009 2:08 AM -
User1940910349 posted
Hell yes, that worked perfectly, thank you!!!!!!!!!!!!!!!!!!!!!!
The only small problem was that Image was an ambigious reference between System.Drawing and System.Web.UI.WebControls. I made a direct reference to it and it worked!
Thursday, February 26, 2009 2:25 AM -
User-2064897223 posted
you are welcome. yes that make ambitious reference with Image web control and drawing.image. So best way is to yse System.Drawing.Image- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 26, 2009 2:43 AM