Is there a built in function to get the width and height of an image inside ASP.NET MVC 3 razor view? Should I use System.Drawing? Or must I delegate to jquery?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Image.FromStream(stream,true,false) will parse the image headers without loading the whole image… takes < 1ms for CPU time, although I/O time may be unacceptable (0-8000ms). If you do this from code-behind, you really should cache the image size data or you will get unacceptable performance under load. You MUST dispose the image afterwards, followed by the stream.
It may be better to put your div sizing logic in the client – much less overhead and much more scalable. jQuery is good at it 🙂
Or, alternatively, just resize the image to the size you want using image.jpg?width=300&heght=200.