检查上传图像的尺寸 [英] Check uploaded image's dimensions
问题描述
我用我的网站上asp.net 3.5和C#。
这里是myquestion:
我有一个上传按钮和ASP:在页面上的图像。一个用户可以从他的电脑上传图片和图像将显示在ASP:图像。但在此之前我展示形象,我想检查上传的图片的宽度和高度。我该怎么做呢?
先谢谢了。
图片IMG = System.Drawing.Image.FromFile(test.jpg放在);
INT宽度= img.Width;
INT高度= img.Height;
您可能需要添加System.Drawing中引用。
您也可以使用 FromStream
的功能,如果你不保存图像到磁盘还,但看你是如何在使用图像(查看用户Image控件),我怀疑它已经在磁盘上。流图像可能会或可能不会比磁盘映像更快。您可能需要做一些分析,看看它有更好的表现。
I'm using asp.net 3.5 and c# on my website. Here is myquestion:
I have an upload button and asp:Image on a page. An user can upload an image from his computer and that image will be displayed in the asp:image. But before I display the image, I would like to check the width and height of the uploaded image. How do I do this?
Thanks in advance.
Image img = System.Drawing.Image.FromFile("test.jpg");
int width = img.Width;
int height = img.Height;
You may need to add the System.Drawing reference.
You may also use the FromStream
function if you have not saved the image to disk yet, but looking at how you're using the image (viewable by user in an Image control), I suspect it's already on disk. Stream to image may or may not be faster than disk to image. You might want to do some profiling to see which has better performance.
这篇关于检查上传图像的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!