我怎样才能使用流的图像尺寸(宽x高) [英] how can I get image size (w x h) using Stream

查看:131
本文介绍了我怎样才能使用流的图像尺寸(宽x高)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的code我使用读取上传的文件,但我需要得到图像的大小,而不是,但不知道什么code,我可以使用

I have this code i am using to read uploaded file, but i need to get size of image instead but not sure what code can i use

HttpFileCollection collection = _context.Request.Files;
            for (int i = 0; i < collection.Count; i++)
            {
                HttpPostedFile postedFile = collection[i];

                Stream fileStream = postedFile.InputStream;
                fileStream.Position = 0;
                byte[] fileContents = new byte[postedFile.ContentLength];
                fileStream.Read(fileContents, 0, postedFile.ContentLength);

我可以得到该文件的权利,但如何检查它的图像(宽度和大小)先生?

I can get the file right but how to check it's image (width and size) sir ?

推荐答案

首先,你必须写映像:

System.Drawing.Image image = System.Drawing.Image.FromStream (new System.IO.MemoryStream(byteArrayHere));

和事后你有:

image.Height.toString(); 

image.Width.toString();

请注意:您可能需要增加一个检查,以确保它是一个上传图片

note: you might want to add a check to be sure it's an image that was uploaded?

这篇关于我怎样才能使用流的图像尺寸(宽x高)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆