locked
A generic error occurred in GDI+. RRS feed

  • Question

  • User455782653 posted
    i am suffered from this problem from last 4 days and still blank regarding this error.
    bellow is the function for uploading the image in three different folder large,view and thumb.


    private void upload_file_large_thumb(String thumb_url, String large, String view, FileUpload fileuploader) { if (Session["folder"].ToString() != "") { String file_name = ""; #region save large Image //save large Image String basepath = "../../images/" + Session["folder"].ToString() + "/"; basepath = Server.MapPath(basepath); file_name = large; //first delete maybe file try { if (File.Exists(basepath + file_name)) File.Delete(basepath + file_name); } catch { } fileuploader.SaveAs(basepath + file_name); fileuploader.Dispose(); System.Drawing.Image.FromStream(fileuploader.PostedFile.InputStream).Dispose(); #endregion #region save view //save view file_name = view; System.Drawing.Image view_image = System.Drawing.Image.FromStream(fileuploader.PostedFile.InputStream); view_image = ResizeImage.resizeImage(view_image, 710); basepath = "../../images/" + Session["folder"].ToString() + "/view/"; basepath = Server.MapPath(basepath); //first delete may be file try { if (File.Exists(basepath + file_name)) File.Delete(basepath + file_name); } catch { } //view_image.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX); view_image.Save(basepath + file_name); view_image.Dispose(); System.Drawing.Image.FromStream(fileuploader.PostedFile.InputStream).Dispose(); view_image = null; GC.Collect(); #endregion #region save thumbnail //save thumbnail file_name = thumb_url; System.Drawing.Image thumb = System.Drawing.Image.FromStream(fileuploader.PostedFile.InputStream); thumb = ResizeImage.resizeImage(thumb, 100); basepath = "../../images/" + Session["folder"].ToString() + "/thumbs/"; basepath = Server.MapPath(basepath); //first delete may be file try { if (File.Exists(basepath + file_name)) File.Delete(basepath + file_name); } catch { } //thumb.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX); thumb.Save(basepath + file_name); thumb.Dispose(); System.Drawing.Image.FromStream(fileuploader.PostedFile.InputStream).Dispose(); thumb = null; GC.Collect(); #endregion fileuploader.PostedFile.InputStream.Close(); } }


    this function well performed when saving a new image but when ever tried to update the image this function will save the large image but gives error regarding view and thumb. if there is any solution plz help me. its take to much time of mine :(
    Wednesday, May 27, 2009 6:19 AM

Answers

  • User-1310709513 posted

     Use view_image.Dispose() before view_image.RotateFlip

    and create a new image (instead of view_image) from stream rather than using the same image object again.

     Look on to this:

    http://forums.asp.net/p/1378591/2906942.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 27, 2009 8:11 AM

All replies

  • User-1310709513 posted

     Use view_image.Dispose() before view_image.RotateFlip

    and create a new image (instead of view_image) from stream rather than using the same image object again.

     Look on to this:

    http://forums.asp.net/p/1378591/2906942.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 27, 2009 8:11 AM
  • User455782653 posted
    i do that also ill save the image with the different image obj after that i dispose the image know what wuld i do
    Wednesday, May 27, 2009 8:18 AM
  • User-1653290890 posted

    Hello Friends,

    as me was blocked on the same issue from last 3-4 days n tried a lot of different attempts for the same but not a single one turned out to be successful.
    But finally today i got the solution.

    After making it double sure that all the permissions are set to WRITE.


    USE string filepath = Server.MapPath("./Images/");
    instead of
    string filepath = Server.MapPath("~//Images//");

    the main issue was while mapping a virtual path
    it starts the path from site folder
    so we need to map with "." instead of "~"

    I have tried the same solution on 3 different projects for the same problem.
    all of them started working very smoothly.
    All the best.....  :)

    Thursday, July 8, 2010 6:24 AM