A generic error occurred in GDI+.

Discussion in 'ASP .Net' started by Jeff, Nov 6, 2008.

  1. Jeff

    Jeff Guest

    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(test.FileBytes);
    System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
    Bitmap img = new Bitmap(new Bitmap(image));
    Font font = new Font("Verdana", 12);
    Graphics gfx = Graphics.FromImage(img);
    gfx.DrawString("Hello World", font, Brushes.CadetBlue, 50, 50);
    img.Save(ms, ImageFormat.Bmp); <<<<-- here
    ms.WriteTo(Response.OutputStream);

    any suggestions?
    Jeff, Nov 6, 2008
    #1
    1. Advertising

  2. Jeff

    bruce barker Guest

    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(test.FileBytes);
    > System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
    > Bitmap img = new Bitmap(new Bitmap(image));
    > Font font = new Font("Verdana", 12);
    > Graphics gfx = Graphics.FromImage(img);
    > gfx.DrawString("Hello World", font, Brushes.CadetBlue, 50, 50);
    > img.Save(ms, ImageFormat.Bmp); <<<<-- here
    > ms.WriteTo(Response.OutputStream);
    >
    > any suggestions?
    >
    >
    bruce barker, Nov 6, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Error Saving Images: A generic error occurred in GDI+.

    =?Utf-8?B?VGltOjouLg==?=, May 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    40,386
    =?Utf-8?B?VGltOjouLg==?=
    May 18, 2004
  2. David Lozzi
    Replies:
    15
    Views:
    6,842
    Steven Cheng[MSFT]
    Dec 20, 2005
  3. Robin van de Water [synthesiSFactory]

    GDI+ is not properly initialized (internal GDI+ error).

    Robin van de Water [synthesiSFactory], Jan 10, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    1,338
    Robin van de Water [synthesiSFactory]
    Jan 10, 2007
  4. =?Utf-8?B?YmFzdWxhc3o=?=

    A generic error occurred in GDI+

    =?Utf-8?B?YmFzdWxhc3o=?=, Jul 24, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    571
    =?Utf-8?B?YmFzdWxhc3o=?=
    Jul 24, 2007
  5. evgenik
    Replies:
    0
    Views:
    1,375
    evgenik
    Nov 26, 2007
Loading...

Share This Page