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+ 中发生一般性错误 的发生,请各位打侠帮我看下,那代码出问题了
HttpContext.Current.Server.MapPath("/DZ/User/UserImages/imgname.jpg")
这是一个目录,你需要提供一个文件名来保存。
bmPhoto.Save(HttpContext.Current.Server.MapPath("/DZ/User/UserImages/"), System.Drawing.Imaging.ImageFormat.Jpeg);