Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net mvc关于上传制作拇指图像_C#_Asp.net Mvc 3 - Fatal编程技术网

C# asp.net mvc关于上传制作拇指图像

C# asp.net mvc关于上传制作拇指图像,c#,asp.net-mvc-3,C#,Asp.net Mvc 3,在图像上传时,我想用不同的名称和大小尺寸保存该图像的副本 [HttpPost] public ActionResult Create(HttpPostedFileBase photo) { string path = System.Configuration.ConfigurationManager.AppSettings["propertyPhotoPath"].ToString(); if ((photo != null) && (photo.Conten

在图像上传时,我想用不同的名称和大小尺寸保存该图像的副本

[HttpPost]
public ActionResult Create(HttpPostedFileBase photo)
{
    string path =  System.Configuration.ConfigurationManager.AppSettings["propertyPhotoPath"].ToString(); 
    if ((photo != null) && (photo.ContentLength > 0))
    {
        var fileName = Path.GetFileName(photo.FileName);
        var pathToSaveOnHdd = Path.Combine(Server.MapPath(path), fileName);
        string dbPhotoPath = string.Format("{0}{1}", path, fileName);
    }
... 
//        to do: make image copy, change dimensions
}

要复制文件,可以使用以下方法。要调整图像大小,有许多技术,包括GDI+、WIC、WPF(这里是a中的一个示例)或NuGet,例如。

您可以将上载的文件从ActionController转换为字节,并更改流的大小,如下所示

Byte[]image1=新字节[photo.ContentLength-1]; HttpPostedFileBase file=photo.PostedFile; file.InputStream.Read(image1,0,file.ContentLength-1); System.IO.MemoryStream ms=新的System.IO.MemoryStream(图像1)

您可以使用graphic类以如下所示的所需大小重新绘制图像 System.Drawing.Image=Image.FromStream(ms)

Graphic Graphic=Graphics.FromImage(图像); graphic.DrawImage(图像,0,0,图像.宽度,图像.高度)