Simple GDI Creation, Browser Error RRS feed

  • Question

  • User-1118161711 posted

    hi , I just started using GDI becouse i want to render some picture at runtime for my project and I am having an issue with browser
    I took the first simple code from 2 books i got and they both work fine on internet explorer but on other browsers like firefox or google chrome i get many question marks and other symboles
    it looks like the browser doesnt understand the format

    here is my code

    Bitmap image = new Bitmap(300, 150);
            Graphics g = Graphics.FromImage(image);
            g.FillRectangle(Brushes.Brown, 1, 1, 298, 148);
            image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);


    Can anyone tell me how I solve this problem please ? it seems like something really basic which i am missing

    Saturday, September 19, 2009 10:40 AM


  • User1633691049 posted


    You cannot just write the output to the response stream. Default the content type of the response stream is text/html. You have to have in mind that you generate an image and you need to tell to the browser what you are sending to it. So you may need to say first:


    Response.ContentType = "image/gif";

    image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); 




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 21, 2009 4:01 AM