保存图片提示System.Drawing.Image.Save 方法而导致 GDI+ 中发生一般性错误 的发生

 Image imgPhoto = Image.FromFile(ImgFile);
            Bitmap bmPhoto = new Bitmap(CutWidth, CutHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Graphics gbmPhoto = Graphics.FromImage(bmPhoto);
            gbmPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, CutWidth, CutHeight), PointX * imgPhoto.Width / PicWidth, PointY * imgPhoto.Height / PicHeight, CutWidth * imgPhoto.Width / PicWidth, CutHeight * imgPhoto.Height / PicHeight, GraphicsUnit.Pixel);
            gbmPhoto.Dispose();


             if (!Directory.Exists(HttpContext.Current.Server.MapPath("/DZ/User/UserImages")))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/DZ/User/UserImages"));
            }
                bmPhoto.Save(HttpContext.Current.Server.MapPath("/DZ/User/UserImages/"), System.Drawing.Imaging.ImageFormat.Jpeg);
                imgPhoto.Dispose();
                gbmPhoto.Dispose();
                bmPhoto.Dispose();

           System.Drawing.Image.Save 方法而导致 GDI+ 中发生一般性错误 的发生,请各位打侠帮我看下,那代码出问题了

慕丝7291255
浏览 768回答 2
2回答

HUX布斯

HttpContext.Current.Server.MapPath("/DZ/User/UserImages/imgname.jpg")

侃侃无极

这是一个目录,你需要提供一个文件名来保存。 bmPhoto.Save(HttpContext.Current.Server.MapPath("/DZ/User/UserImages/"), System.Drawing.Imaging.ImageFormat.Jpeg);
打开App,查看更多内容
随时随地看视频慕课网APP