Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I get image size (w x h) using Stream

Tags:

I have this code i am using to read uploaded file, but i need to get size of image instead but not sure what code can i use

HttpFileCollection collection = _context.Request.Files;             for (int i = 0; i < collection.Count; i++)             {                 HttpPostedFile postedFile = collection[i];                  Stream fileStream = postedFile.InputStream;                 fileStream.Position = 0;                 byte[] fileContents = new byte[postedFile.ContentLength];                 fileStream.Read(fileContents, 0, postedFile.ContentLength); 

I can get the file right but how to check it's image (width and size) sir ?

like image 423
Mathematics Avatar asked May 20 '13 13:05

Mathematics


People also ask

How do you calculate stream size?

Multiply the average depth of the stream by the width of the stream to find the area in ft2. Divide the distance traveled by the average travel time to find the velocity of the stream in ft/sec. Multiply the velocity of the stream by a correction factor. This is the corrected velocity of the stream.

How do I find out the size of an image?

You can also right-click on an image & choose properties from the drop-down menu. A new window will appear with several tabs. You'll click the details tab, and there you'll find you image size and dimensions.

How do I know the pixel size of an image online?

Right-click on the image and then select "Properties." A window will appear with the image's details. Go to the "Details" tab to see the image's dimensions and resolution.


1 Answers

First you have to write the image:

System.Drawing.Image image = System.Drawing.Image.FromStream (new System.IO.MemoryStream(byteArrayHere)); 

and afterwards you have the :

image.Height.ToString();  

and the

image.Width.ToString(); 

note: you might want to add a check to be sure it's an image that was uploaded?

like image 86
Rob Avatar answered Nov 14 '22 09:11

Rob