Note that there are some explanatory texts on larger screens.

plurals
  1. POGDI+ Generic Error
    primarykey
    data
    text
    <p>When my images are being loaded from my database on my web server, I see the following error:</p> <blockquote> <p>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)</p> </blockquote> <p>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?</p> <p>Note - This works if I test it on my local machine, but not when I deploy it to my web server.</p> <pre><code>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("&lt;p&gt;Error: Image ID is not valid - image may have been deleted from the database.&lt;/p&gt;"); } } </code></pre> <p>The error occurs on the line:</p> <blockquote> <p>image.Save(context.Response.OutputStream, ImageFormat.Png);</p> </blockquote> <p><strong>UPDATE</strong></p> <p>I've changed my code to this, bit the issue still happens:</p> <pre><code>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); } } </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload