Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Asp.net mvc MVC4-上传图像-通用GDI+;错误_Asp.net Mvc_Image_File Upload_Gdi - Fatal编程技术网

Asp.net mvc MVC4-上传图像-通用GDI+;错误

Asp.net mvc MVC4-上传图像-通用GDI+;错误,asp.net-mvc,image,file-upload,gdi,Asp.net Mvc,Image,File Upload,Gdi,我试图上传一个图像,当我尝试image.Save()时,我得到一个“generic GDI+”错误。任何帮助都会很好 // This action handles the form POST and the upload [HttpPost] public ActionResult Index(HttpPostedFileBase file, string filename) { // Verify that the user selected a

我试图上传一个图像,当我尝试image.Save()时,我得到一个“generic GDI+”错误。任何帮助都会很好

    // This action handles the form POST and the upload
    [HttpPost]
    public ActionResult Index(HttpPostedFileBase file, string filename)
    {
        // Verify that the user selected a file
        if (file != null && file.ContentLength > 0)
        {                
            string location = "~/Content/Images/Specials/" + "rttest" + ".jpg";
            Bitmap bitmap = new Bitmap(file.InputStream);
            Image image = (Image)bitmap;
            image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
            image.Save(location);            
        }
        // redirect back to the index action to show the form once again
        return RedirectToAction("Index");
    }
GDI+无法访问“~/Content/Images/Specials/…”的位置,因为它不是物理路径。您需要使用
Server.MapPath()
将虚拟路径映射到物理路径

 string location = Server.MapPath("~/Content/Images/Specials/" + "rttest" + ".jpg");
另外,连接路径的一部分,然后是“rrest”然后是“.jpg”,这很奇怪。在投入生产之前,您可能想了解一下这一点,这样您就不会一遍又一遍地覆盖图像