A Generic Error Occurred In Gdi Outputstream
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of
A Generic Error Occurred In Gdi Bitmap Save C#
this site About Us Learn more about Stack Overflow the company Business Learn a generic error occurred in gdi c# image save more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
A Generic Error Occurred In Gdi In C# Windows Application
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up C# a generic error occurred in gdi+ at system drawing image save - Outputting image to response output stream giving GDI+ error up vote 36 down vote favorite 12 When outputting an image to the output stream, does it require temporary storage? I get the "generic GDI+" error that is usually associated with folder permission error when saving an image to file. The only thing I'm doing to the image is adding some text. I a generic error occurred in gdi+ crystal reports still get the error even when I output the image straight without modifications. For example, doing this will give me the error: using (Bitmap image = new Bitmap(context.Server.MapPath("images/stars_5.png"))) { image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); } Everything works fine on my local machine running Windows 7 with IIS 7.5 and ASP.NET 2.0. The problem is occurring on the QA server which is running Windows Server 2003 with IIS 6 and ASP.NET 2.0. The line that's giving the error is: image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); Here's the stack trace: [ExternalException (0x80004005): A generic error occurred in GDI+.] System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) +378002 System.Drawing.Image.Save(Stream stream, ImageFormat format) +36 GetRating.ProcessRequest(HttpContext context) in d:\inetpub\wwwroot\SymInfoQA\Apps\tools\Rating\GetRating.ashx:54 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 c# asp.net gdi+ share|improve this question asked Apr 12 '11 at 1:00 Daniel 3581314 Are you using any source control, per chance? –Christopher Harris Apr 12 '11 at 1:17 add a comment| 2 Answers 2 active oldest votes up vote 81 down vote accepted PNGs (and other formats) need to be saved to a seekable stream. Using an intermediate MemoryStream will do the trick: using (Bitmap image = new Bitmap(context.Server.MapPath("images/stars_5.png"))) { using(MemoryStream ms = new
here for a quick overview of the site Help Center Detailed answers to
A Generic Error Occurred In Gdi+ Windows 7
any questions you might have Meta Discuss the workings and policies a generic error occurred in gdi+ vb of this site About Us Learn more about Stack Overflow the company Business Learn more
A Generic Error Occurred In Gdi+ Selenium
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack http://stackoverflow.com/questions/5629251/c-sharp-outputting-image-to-response-output-stream-giving-gdi-error Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up A Generic error occured in GDI+ in Bitmap.Save method up vote 26 down vote favorite 8 I am working on to upload and same a thumnail copy of http://stackoverflow.com/questions/15862810/a-generic-error-occured-in-gdi-in-bitmap-save-method that image in a thumbnail forder. I am using following link: http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx but newBMP.Save(directory + "tn_" + filename); is causing exception "A generic error occurred in GDI+." I have tried to give permission on folder, also tried to use a new separate bmp object when saving. Edit: protected void ResizeAndSave(PropBannerImage objPropBannerImage) { // Create a bitmap of the content of the fileUpload control in memory Bitmap originalBMP = new Bitmap(fuImage.FileContent); // Calculate the new image dimensions int origWidth = originalBMP.Width; int origHeight = originalBMP.Height; int sngRatio = origWidth / origHeight; int thumbWidth = 100; int thumbHeight = thumbWidth / sngRatio; int bannerWidth = 100; int bannerHeight = bannerWidth / sngRatio; // Create a new bitmap which will hold the previous resized bitmap Bitmap thumbBMP = new Bitmap(originalBMP, thumbWidth, thumbHeight); Bitmap bannerBMP = new Bitmap(originalBMP, bannerWidth, bannerHeight); // Create a graphic based on the new bitmap Graphics oGraphics = Graphics.FromImage(thumbBMP); // Set the p
generic error occurred in GDI+. Writing PNG to Response.OutputStream - System.Runtime.InteropServices.ExternalException: A generic error occurred in https://github.com/imclem/Highcharts-export-module-asp.net/issues/6 GDI+. Last revision: May 22, 2012 When you try to save a Bitmap in a a generic PNG format directly to Response.OutputStream like this:Bitmap bmp = DayPilotMonth1.ExportBitmap(); bmp.Save(Response.OutputStream, ImageFormat.Png);You may get the following error:System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.You can solve this problem by using a a generic error temporary MemoryStream:// PNG requires random access to the output stream using (MemoryStream mem = new MemoryStream()) { bmp.Save(mem, ImageFormat.Png); mem.WriteTo(Response.OutputStream); } Bitmap.Save() method requires random access to the output memory stream. This is not possible in case of a Response.OutputStream and an exception is thrown. Related How to add a header to the exported calendar image (PNG) Sys.WebForms.PageRequestManagerParserErrorException on PNG export button click How to force download of exported calendar/scheduler image (PNG) How to save the exported PNG image to a file (without a web page) Copyright © 2016 daypilot.org
Support Search GitHub This repository Watch 27 Star 107 Fork 69 imclem/Highcharts-export-module-asp.net Code Issues 2 Pull requests 0 Projects 0 Wiki Pulse Graphs New issue A generic error occurred in GDI+ exporting png on IIS7.0 #6 Closed GianlucaMaggio opened this Issue Feb 29, 2012 · 6 comments Projects None yet Labels None yet Milestone No milestone Assignees No one assigned 2 participants GianlucaMaggio commented Feb 29, 2012 Exporting to png generate an error: [ExternalException (0x80004005): A generic error occurred in GDI+.] System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) +378002 System.Drawing.Image.Save(Stream stream, ImageFormat format) +36 Tek4.Highcharts.Exporting.Exporter.WriteToStream(Stream outputStream) +234 Tek4.Highcharts.Exporting.Exporter.WriteToHttpResponse(HttpResponse httpResponse) +67 Tek4.Highcharts.Exporting.ExportChart.ProcessExportRequest(HttpContext context) +305 Tek4.Highcharts.Exporting.HttpHandler.ProcessRequest(HttpContext context) +7 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 I found that the problem is known and a solution is to use a MemoryStream prior to write to response. This is my code to solve the issue: internal void WriteToHttpResponse(HttpResponse httpResponse) { httpResponse.ClearContent(); httpResponse.ClearHeaders(); httpResponse.ContentType = this.ContentType; httpResponse.AddHeader("Content-Disposition", this.ContentDisposition); if (this.ContentType == "image/png") { // for png we need to use a memory stream using (MemoryStream ms = new MemoryStream()) { WriteToStream(ms); ms.WriteTo(httpResponse.OutputStream); } } else { WriteToStream(httpResponse.OutputStream); } Collaborator Tek4 commented Feb 29, 2012 Nice work. Could you provide a link to where this is discussed as a known issue? I'd like to read more. GianlucaMaggio commented Feb 29, 2012 Sure. I found this: http://stackoverflow.com/questions/5629251/c-sharp-outputting-image-to-response-output-stream-giving-gdi-error GianlucaMaggio commented Feb 29, 2012 And also this: http://www.west-wind.com/weblog/posts/2006/Oct/19/Common-Problems-with-rendering-Bitmap