简体   繁体   English

如何使用asp.net获取使用ajaxfileupload上传的图像宽度和高度

[英]How to get image width and height uploaded using ajaxfileupload asp.net

I think ajaxcontroltoolkit:ajaxfileupload has too many bugs and wane. 我认为ajaxcontroltoolkit:ajaxfileupload有太多的错误和衰落。 since I'm using this component frequently in my projects, I overcome to many serious disturbing bugs and functionality of this control. 由于我在项目中经常使用此组件,因此克服了许多严重的令人不安的错误和该控件的功能。 Now, I seriously need to get uploaded image width and height using ajaxfileupload before I save it to check either width or height are correct and based on retrieved information, informing users in case of image width and height are not compatible and then prevent the process to go further and save the picture. 现在,我非常需要使用ajaxfileupload获取上传的图像宽度和高度,然后再保存以检查宽度或高度是否正确并根据检索到的信息,在图像宽度和高度不兼容时通知用户,然后阻止该过程走得更远并保存图片。 Any Ideas please?! 有任何想法吗?

HTML Side: HTML面:

<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
        onuploadcomplete="AjaxFileUpload1_UploadComplete" ThrobberID="myThrobber" MaximumNumberOfFiles="1" AllowedFileTypes="jpg,jpeg"/>

Behind Code: 背后的代码:

protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
    string filePath = "~/upload/" + e.FileName;
    AjaxFileUpload1.SaveAs(filePath);

}

AjaxFileUpload just handles the upload but doesn't give you any information about the file itself. AjaxFileUpload只处理上传,但不提供有关文件本身的任何信息。 You need to use something like 您需要使用类似

System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath(filePath));
width = objImage.Width;
height = objImage.Height; 

If you do not want to load the file into memory, you can check How do I reliably get an image dimensions in .NET without loading the image? 如果您不想将文件加载到内存中,可以检查如何在不加载图像的情况下可靠地在.NET中获取图像尺寸? or Getting image dimensions without reading the entire file . 或在不读取整个文件的情况下获取图像尺寸

An alternative would be to check image width and height on client side, using a tool like Plupload or a similar one. 一种替代方法是使用Plupload之类的工具或类似工具在客户端检查图像的宽度和高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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