C# 调整已作为WebAPI控制器中的多部分/表单数据上载的图像的大小

C# 调整已作为WebAPI控制器中的多部分/表单数据上载的图像的大小,c#,asp.net-web-api,asp.net-web-api2,C#,Asp.net Web Api,Asp.net Web Api2,我得到一个图像,该图像已使用multipart/form data使用wait Request.Content.ReadAsMultipartAsync(provider)上传到Web API方法,如下所示: // Read the form data. await Request.Content.ReadAsMultipartAsync(provider); foreach (MultipartFileData item in provider.FileData) { string

我得到一个图像,该图像已使用
multipart/form data
使用
wait Request.Content.ReadAsMultipartAsync(provider)
上传到Web API方法,如下所示:

// Read the form data.
await Request.Content.ReadAsMultipartAsync(provider);

foreach (MultipartFileData item in provider.FileData)
{
    string name = item.Headers.ContentDisposition.FileName.Replace("\"", "");
    newFileName = Guid.NewGuid() + Path.GetExtension(name);
    File.Move(item.LocalFileName, Path.Combine(rootPath, newFileName));
    Uri baseuri = new Uri(Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.PathAndQuery, string.Empty));
    string fileRelativePath = rootPath + newFileName;
    Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath));
    savedFilePath.Add(fileFullPath.ToString());
    Dictionary<string, string> dictionary = new Dictionary<string, string>();
    dictionary.Add(fieldID, newFileName);
    HttpContext.Current.Session[fieldID] = dictionary;
}
//读取表单数据。
wait Request.Content.ReadAsMultipartAsync(提供程序);
foreach(provider.FileData中的MultipartFileData项)
{
字符串名称=item.Headers.ContentDisposition.FileName.Replace(“\”,”);
newFileName=Guid.NewGuid()+Path.GetExtension(名称);
Move(item.LocalFileName,Path.Combine(rootPath,newFileName));
Uri baseuri=新Uri(Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.PathAndQuery,string.Empty));
字符串fileRelativePath=rootPath+newFileName;
urifilefullpath=新Uri(baseuri,virtualPath.ToAbsolute(fileRelativePath));
savedFilePath.Add(fileFullPath.ToString());
字典=新字典();
添加(fieldID,newFileName);
HttpContext.Current.Session[fieldID]=字典;
}
在将图像保存到磁盘之前,我需要调整其大小。我不确定是否可以在运行时执行此操作。有什么想法吗