Saving An image,A generic error occurred in GDI+

后端 未结 2 1404
旧巷少年郎
旧巷少年郎 2021-01-20 05:32

i get an

A generic error occurred in GDI+

exception when I call img.Save(path, jpegCodec, encoderParams);
here

2条回答
  •  独厮守ぢ
    2021-01-20 06:02

    public ActionResult CropImage(string hdnx, string hdny, string hdnw, string hdnh)
    {
        string fname = "pool.jpg";
        string fpath = Path.Combine(Server.MapPath("~/images"), fname);
        Image oimg = Image.FromFile(fpath);
        Rectangle cropcords = new Rectangle(
        Convert.ToInt32(hdnx),
        Convert.ToInt32(hdny),
        Convert.ToInt32(hdnw),
        Convert.ToInt32(hdnh));
        string cfname, cfpath;
        Bitmap bitMap = new Bitmap(cropcords.Width, cropcords.Height,img.PixelFormat);
    
        Graphics grph = Graphics.FromImage(bitMap);
        grph.DrawImage(oimg, new Rectangle(0, 0, bitMap.Width, bitMap.Height), cropcords, GraphicsUnit.Pixel);
        cfname = "crop_" + fname;
        cfpath = Path.Combine(Server.MapPath("~/cropimages"), cfname);
        bitMap.Save(cfpath);
    
        return Json("success",JsonRequestBehavior.AllowGet);
    }
    

提交回复
热议问题