CodeToad
CodeToad

Reputation: 4734

efficient way to check width/height of httppostedfilebase image in c# .net

On upload of an image file, I want to check its width/height. So far the only way I have found to this is to create an image file out of it either though accessing the memory stream or saving the file o disk, both of which are memory intensive operations.

Perhaps its possible to read the metadata of the file, though I suspect that differences between image types will make this process cumbersome.

Upvotes: 3

Views: 4654

Answers (2)

RayLoveless
RayLoveless

Reputation: 21108

Pretty sure there's not a way to do it on the server side without first converting it to an image because the HttpPostedFileBase type could be really any type of file...not just an image.

This may be solution on the client side though.

Upvotes: 1

Антон К
Антон К

Reputation: 101

// File - have type HttpPostedFileBase
var img = Drawing.Image.FromStream(File.InputStream, true, true);
int w = img.Width;
int h = img.Height;

Upvotes: 10

Related Questions