locked
Writing Bitmap to Response.OutputStream - Generic Error Occured in GDI+ RRS feed

  • Question

  • User-934613810 posted

    Hi,

    This is what I'm trying to do when I get the error on the server (it works on my local machine):

    System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image); 
    image.Dispose();

    Response.ContentType = "image/bmp";
    bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
    bmp.Dispose();

    I don't think it can be a permissions problem because this works on the server:

    System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image);
    image.Dispose();

    Response.ContentType = "image/jpeg";
    bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
    bmp.Dispose();

    So how do I get this to work for a bitmap?

    Thanks,
    Dan

    Wednesday, August 25, 2010 11:10 AM

Answers

  • User-934613810 posted

    After trying a bunch of things I came up with this:

    Response.WriteFile(filepath);
    Response.Output.Flush();
    Response.End();

    Skipping the encoding and just writing the file.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 25, 2010 1:59 PM