A generic error occurred in GDI+.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    A generic error occurred in GDI+.

    hi

    asp.net 2.0

    I'm experimenting with GDI+ in asp.net and get an "A generic error occurred
    in GDI+." exception.

    Below is my code, I've marked a line with "<<<<-- here". It's here the
    exception is thrown.

    (test.FileBytes - FileBytes is an array of bytes) test is an enity class,
    and I'm storing the images in the database. When tested the image which
    test.FileBytes is based on is a GIF

    MemoryStream ms = new MemoryStream(te st.FileBytes);
    System.Drawing. Image image = System.Drawing. Image.FromStrea m(ms);
    Bitmap img = new Bitmap(new Bitmap(image));
    Font font = new Font("Verdana", 12);
    Graphics gfx = Graphics.FromIm age(img);
    gfx.DrawString( "Hello World", font, Brushes.CadetBl ue, 50, 50);
    img.Save(ms, ImageFormat.Bmp ); <<<<-- here
    ms.WriteTo(Resp onse.OutputStre am);

    any suggestions?


  • bruce barker

    #2
    Re: A generic error occurred in GDI+.

    its unclear what you are trying to do, but you error is probably you
    usage of the memory stream. you create a non-resizeable memory stream,
    and read to the end. then you try to write to it without a seek to the
    start, so there is nowhere to write (you also do no check that it would
    fit anyway). also the bitmap class recommends not using the same stream
    for reading and writing.

    -- bruce (sqlwork.com)

    Jeff wrote:
    hi
    >
    asp.net 2.0
    >
    I'm experimenting with GDI+ in asp.net and get an "A generic error occurred
    in GDI+." exception.
    >
    Below is my code, I've marked a line with "<<<<-- here". It's here the
    exception is thrown.
    >
    (test.FileBytes - FileBytes is an array of bytes) test is an enity class,
    and I'm storing the images in the database. When tested the image which
    test.FileBytes is based on is a GIF
    >
    MemoryStream ms = new MemoryStream(te st.FileBytes);
    System.Drawing. Image image = System.Drawing. Image.FromStrea m(ms);
    Bitmap img = new Bitmap(new Bitmap(image));
    Font font = new Font("Verdana", 12);
    Graphics gfx = Graphics.FromIm age(img);
    gfx.DrawString( "Hello World", font, Brushes.CadetBl ue, 50, 50);
    img.Save(ms, ImageFormat.Bmp ); <<<<-- here
    ms.WriteTo(Resp onse.OutputStre am);
    >
    any suggestions?
    >
    >

    Comment

    Working...