Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:33:07+00:00 2026-05-27T04:33:07+00:00

When my images are being loaded from my database on my web server, I

  • 0

When my images are being loaded from my database on my web server, I see the following error:

A generic error occurred in GDI+. at
System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder,
EncoderParameters encoderParams) at
System.Drawing.Image.Save(Stream stream, ImageFormat format) at
MyWeb.Helpers.ImageHandler.ProcessRequest(HttpContext context)

All my code is attempting to do is load the image, can anybody take a look and let me know what I’m doing wrong?

Note – This works if I test it on my local machine, but not when I deploy it to my web server.

public void ProcessRequest(HttpContext context)
{
    context.Response.Clear();          

    if (!String.IsNullOrEmpty(context.Request.QueryString["imageid"]))         
    {
        int imageID = Convert.ToInt32(context.Request.QueryString["imageid"]);
        int isThumbnail = Convert.ToInt32(context.Request.QueryString["thumbnail"]);

        // Retrieve this image from the database
        Image image = GetImage(imageID);

        // Make it a thumbmail if requested
        if (isThumbnail == 1)
        {
            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
            image = image.GetThumbnailImage(200, 200, myCallback, IntPtr.Zero);
        }

        context.Response.ContentType = "image/png";             

        // Save the image to the OutputStream             
        image.Save(context.Response.OutputStream, ImageFormat.Png);
    }         
    else         
    {             
        context.Response.ContentType = "text/html";             
        context.Response.Write("<p>Error: Image ID is not valid - image may have been deleted from the database.</p>");         
    } 
}

The error occurs on the line:

image.Save(context.Response.OutputStream, ImageFormat.Png);

UPDATE

I’ve changed my code to this, bit the issue still happens:

var db = new MyWebEntities();

var screenshotData = (from screenshots in db.screenshots
                      where screenshots.id == imageID
                      select new ImageModel
                      {
                           ID = screenshots.id,
                           Language = screenshots.language,
                           ScreenshotByte = screenshots.screen_shot,
                           ProjectID = screenshots.projects_ID
                      });

foreach (ImageModel info in screenshotData) 
 {
    using (MemoryStream ms = new MemoryStream(info.ScreenshotByte))
    {
         Image image = Image.FromStream(ms);

         // Make it a thumbmail if requested
         if (isThumbnail == 1)
         {
              Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
              image = image.GetThumbnailImage(200, 200, myCallback, IntPtr.Zero);
         }

         context.Response.ContentType = "image/png";

         // Save the image to the OutputStream             
         image.Save(context.Response.OutputStream, ImageFormat.Png);

    } }

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:33:08+00:00Added an answer on May 27, 2026 at 4:33 am

    Probably for the same reason that this guy was having problems – because the for a lifetime of an Image constructed from a Stream, the stream must not be destroyed.

    So if your GetImage function constructs the returned image from a stream (e.g. a MemoryStream) and then closes the stream before returning the image then the above will fail. My guess is that your GetImage looks a tad like this:

    Image GetImage(int id)
    {
        byte[] data = // Get data from database
        using (MemoryStream stream = new MemoryStream(data))
        {
            return Image.FromStream(data);
        }
    }
    

    If this is the case then try having GetImage return the MemoryStream (or possibly the byte array) directrly so that you can create the Image instance in your ProcessRequest method and dispose of the stream only when the processing of that image has completed.

    This is mentioned in the documentation but its kind of in the small print.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If too many images are being loaded from the server at once (or over
Is flash the best bet to keep images from being stolen? Is there any
I have implemented the following set up (after being requested): slideshow of images changing,
I have gallery.php that loads images with src path from a database. I also
I am using a gridview with image adapter. The adapter load images from web
How to show loading image when a big image is being loaded? As an
I'm trying to remove the background image on a page that's being loaded via
My problem is that my 300 images are being added to UiScrollView and shows
I'm creating a game where a lot of images are being used in Actionscript
Is there any reason why images are not being displayed if I place it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.