简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM