locked
A generic error occurred in GDI+ RRS feed

  • Question

  • User-455811767 posted

    Hi

    I got this Error When Iam Tried to save image into .png;

    a generic error occured in GD+

    My code like this

    Byte[] image = MapOpen();
                                //webService.MapOpen(width, height, boundingbox, format,layers);
                            if (image != null)
                            {
                                using (MemoryStream stream = new MemoryStream(image))
                                {
                                    System.Drawing.Image oImg = System.Drawing.Image.FromStream(stream);
                                    this.Response.ContentType = "image/png";
                                    oImg.Save(this.Response.OutputStream, ImageFormat.Png);
                                    oImg.Dispose();
                                }
                            }


    When I saved as .Jpeg,I didn't get any Error.it works fine,but when i changed into ImageFormat.png it will showing error.

    Please Have a look at my problem

    thanks


    Thursday, August 27, 2009 7:22 AM

Answers

  • User503727708 posted

    using(Image img = new Bitmap(Server.MapPath("test.png")))
    {
        using(Graphics g = Graphics.FromImage(img))
        {
        g.DrawString("ProfessorX", new Font("tahoma", 12f), new     SolidBrush(Color.Black), new Point(50,50));
        }
       
        Response.Clear();
        Response.ContentType = "image/png";

        using(MemoryStream stream = new MemoryStream())
        {

            img.Save(stream, ImageFormat.Png);


           stream.WriteTo(
    Response.OutputStream);
        }
    }



    in this post by

    http://forums.asp.net/p/975883/1237972.aspx

    http://forums.asp.net/members/Fredrik-K.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 27, 2009 10:25 AM

All replies

  • User503727708 posted

    using(Image img = new Bitmap(Server.MapPath("test.png")))
    {
        using(Graphics g = Graphics.FromImage(img))
        {
        g.DrawString("ProfessorX", new Font("tahoma", 12f), new     SolidBrush(Color.Black), new Point(50,50));
        }
       
        Response.Clear();
        Response.ContentType = "image/png";

        using(MemoryStream stream = new MemoryStream())
        {

            img.Save(stream, ImageFormat.Png);


           stream.WriteTo(
    Response.OutputStream);
        }
    }



    in this post by

    http://forums.asp.net/p/975883/1237972.aspx

    http://forums.asp.net/members/Fredrik-K.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 27, 2009 10:25 AM
  • User-455811767 posted

    Thanks for solved my problem,its working very Nice..


    Friday, August 28, 2009 12:13 AM