首页 > Web开发 > 详细

A generic error occurred in GDI+. 上传图片报错

时间:2015-02-05 12:57:08      阅读:645      评论:0      收藏:0      [点我收藏+]

代码就不说了,因为本地测试 ok,

服务端 就不行 ,服务器 环境 阿里云 win2008 r2  64 位

原因 是我没有这是 文件加权限 :

技术分享

左边 的 少了 权限~

代码 :含义是 网络图片 裁剪 保存 到本地 ,本地 再 存储 到 七牛 云存储。

  public static string Crop(string ImgUrl, int Width, int Height, int X, int Y)
    {
      string path = "C:\\DescripttionImg\\";
      string Temp = "";
      string path_Temp = "";
      try
      {

        if (ImgUrl.IndexOf(?) > 0)
        {
          Temp = ImgUrl.Remove(ImgUrl.IndexOf(?));
          Temp = "Head_" + Temp.Substring(Temp.LastIndexOf(/) + 1);
        }
        else
        {
          Temp = "Head_" + ImgUrl.Substring(ImgUrl.LastIndexOf(/) + 1);
        }


        WebRequest WebReq = WebRequest.Create(ImgUrl);
        WebReq.Method = "GET";
        var img = System.Drawing.Image.FromStream(WebReq.GetResponse().GetResponseStream());
        using (System.Drawing.Image OriginalImage = img)
        {
          using (Bitmap bmp = new Bitmap(Width, Height))
          {
            bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);
            using (Graphics Graphic = Graphics.FromImage(bmp))
            {
              Graphic.SmoothingMode = SmoothingMode.AntiAlias;
              Graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
              Graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
              Graphic.DrawImage(OriginalImage, new Rectangle(0, 0, Width, Height), X, Y, Width, Height, GraphicsUnit.Pixel);
              //MemoryStream ms = new MemoryStream();
              path_Temp = path + Temp;
              bmp.Save(path_Temp);
              WebReq.Abort();
              //return ms.GetBuffer();
            }
          }
        }
        Qiniu_API.PutFile(path_Temp, Temp);
        return string.Format("http://{0}/{1}", Qiniu_API.Domain, Temp);
        // 
      }

      catch (Exception ex)
      {
        KT_Product_ShowEntities tempconn = new KT_Product_ShowEntities();

        tempconn.Err_Log.Add(new Err_Log()
        {
          CreateTime = DateTime.Now,
          form_no = "",
          Msg = ex.Message,
          StackTrace = ex.StackTrace,
          sys_user = "",
          TargetSite = ex.TargetSite.ToString(),
          UserName = "mail"
        });
        tempconn.SaveChanges();

        throw (ex);
      }
      finally
      {

      }
    }

 

A generic error occurred in GDI+. 上传图片报错

原文:http://www.cnblogs.com/bingguang/p/4274270.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!