C# 从流更改图像大小

C# 从流更改图像大小,c#,azure,model-view-controller,C#,Azure,Model View Controller,我已经在这里寻找帮助,但没有什么完全符合我的需要。我有一个上传的图像,我想在它保存到azure之前更改大小 所以目前我的代码是: public ActionResult UserDetails(HttpPostedFileBase photo) { var inputFile = new Photo() { FileName = photo.FileName,

我已经在这里寻找帮助,但没有什么完全符合我的需要。我有一个上传的图像,我想在它保存到azure之前更改大小

所以目前我的代码是:

public ActionResult UserDetails(HttpPostedFileBase photo)
    {     var inputFile = new Photo()
            {
                FileName = photo.FileName,                    
                Data = () => photo.InputStream
            };
//then I save to Azure
例如,如何将photo.InputStream更改为100x100 px?

以下是我的操作方法:

byte[] imageBytes; 

//Of course image bytes is set to the bytearray of your image      

using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
    {
        using (Image img = Image.FromStream(ms))
        {
            int h = 100;
            int w = 100;

            using (Bitmap b = new Bitmap(img, new Size(w,h)))
            {
                using (MemoryStream ms2 = new MemoryStream())
                {
                    b.Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg);
                    imageBytes = ms2.ToArray();
                }
            }
        }                        
    }    
从那里,我使用
MemoryStream
上传。我使用blob存储并使用
UploadFromStreamAsync
加载到blob

这是它的基本观点。
~干杯

到目前为止你都试了些什么?在线上有很多教程介绍如何在C#中调整图像的大小。我可以使用WebImage更改图像大小,但我只能将图像作为WebImage对象保存,无法使用:Data=()=>WebImageObject…..保存图像。。。。。不起作用,谢谢,我将在星期一试用。:)