开发者

Image width and height in ASP.NET MVC 3 view

开发者 https://www.devze.com 2023-03-17 11:59 出处:网络
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.FromStre

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号