Is there a built in function to get the width and height of an image inside ASP.NET MVC 3 razor view? 开发者_StackOverflow中文版Should I use System.Drawing? Or must I delegate to jquery?
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.
精彩评论