ASP.NET如何获取上传图片尺寸(是指宽高)

1.采用客户端javascript可以取得图片大小

<input id="FileUpload" type="file" size="27" name="FileUpload" onpropertychange="javascript:img2.src=this.value;">
<img id="img2" src="" style="visibility:hidden;position:absolute;top=-10000"/>
<input type="button" value="获取" onclick="javascript:abc();">
<script language="javascript">
function abc()
{
alert(img2.width);
}



2.采用流取得图片大小

Stream stream=file.PostedFile.InputStream;
System.Drawing.Image image=System.Drawing.Image.FromStream(stream);

Image.Width
Image.Height



3.使用文件得到图片大小
 

System.Drawing.Image image=System.Drawing.Image.FromFile(图片路径)
Image.Width
Image.Height

转自百度知道 大神回答:https://zhidao.baidu.com/question/252185066.html?qbl=relate_question_1&word=C%23%20%D1%E9%D6%A4%CD%BC%C6%AC%B3%A4%BA%CD%BF%ED

猜你喜欢

转载自blog.csdn.net/love_pgme/article/details/84401537