Bitmap Save To Stream A Generic Error Occurred In Gdi
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings c# bitmap save a generic error occurred in gdi+ and policies of this site About Us Learn more about Stack Overflow a generic error occurred in gdi c# image save the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation a generic error occurred in gdi image save vb net Tags Users Badges Ask Question 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
How To Solve A Generic Error Occurred In Gdi+
only takes a minute: Sign up A generic error occurred in GDI+, JPEG Image to MemoryStream up vote 198 down vote favorite 38 This seems to be a bit of an infamous error all over the web. So much so that I have been unable to find an answer to my problem as my scenario doesn't fit. An exception gets a generic error occurred in gdi in c# windows application thrown when I save the image to the stream. Weirdly this works perfectly with a png but gives the above error with jpg and gif which is rather confusing. Most similar problem out there relate to saving images to files without permissions. Ironically the solution is to use a memory stream as I am doing.... public static byte[] ConvertImageToByteArray(Image imageToConvert) { using (var ms = new MemoryStream()) { ImageFormat format; switch (imageToConvert.MimeType()) { case "image/png": format = ImageFormat.Png; break; case "image/gif": format = ImageFormat.Gif; break; default: format = ImageFormat.Jpeg; break; } imageToConvert.Save(ms, format); return ms.ToArray(); } } More detail to the exception. The reason this causes so many issues is the lack of explanation :( System.Runtime.InteropServices.ExternalException was unhandled by user code Message="A generic error occurred in GDI+." Source="System.Drawing" ErrorCode=-2147467259 StackTrace: at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(Stream stream, ImageFormat format) at Caldoo.Infrastructure.PhotoEditor.ConvertImageToByteArray(Image imageToConvert) in C:\Users\Ian\SVN\Caldoo\Caldoo.Coordinator\PhotoEditor.cs:line 139 at Caldoo.Web.Controllers.PictureController.Croppable() in C:\Users\Ian\SVN\Caldoo\Caldoo.Web\Controllers\PictureController.cs:line 132 at lambda_method(ExecutionScope , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActio
have a write permission on some directory. For example, if you are trying to save the Image from the memory stream to the file system , you a generic error occurred in gdi+. asp.net c# may get that error. I also faced that error when I was using Infragistics
System.runtime.interopservices.externalexception (0x80004005): A Generic Error Occurred In Gdi+.
charts control , the control was trying to create a temporary chart in ChartImages folder and my application was not
A Generic Error Occurred In Gdi+ Windows 7
given the write permission. Please if you are using XP, make sure to add write permission for the aspnet account on that folder. If you are using windows server (2003,2008) or Vista, make sure http://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream that add write permission for the Network service account. Hope it help some one. 23 Comments Na, _one_ of the possible errors could be the one, you described. The "Generic error" in fact is used in certain scenarios. It means "we were to lazy to write better error return code". This really sucks. Uwe - Saturday, February 28, 2009 8:44:55 PM Well, at least that's based on http://weblogs.asp.net/anasghanem/solving-quot-a-generic-error-occurred-in-gdi-quot-exception my experience and on the problems i faced. I know that there is many other causes of that problem,but that's what i know until this time. anas - Saturday, February 28, 2009 8:57:28 PM I think it's the most common error so permissions should always be checked first. SGWellens - Saturday, February 28, 2009 9:18:12 PM It might not be that you don't have write permissions, but a sharing violation might be in effect. Common scenario that this happens: 1) Read an image into a Bitmap object 2) Manipulate the bitmap 3) Wanting to write back the bitmap to overwrite the original image file you read in step 1. This can happen because the Bitmap implementation seems to be as lazy as possible. It can choose the just remember the path that was the source of the image bits (or even a handle to the opened file they came from). This then means your software has the original image file open, causing this problem when you try to overwrite it in step three. To work around this use some simple code in an intermediate step (let's say 1a) that creates a new, blank Bitmap object with the same width/height/colordepth as the
> .NET Framework Class Libraries Question 0 Sign in to vote Hello All,I was just going to play around by generating some bitmaps programatically.I started off with this simple example, a generic expecting everything to go smoothly, but have run into a strange error.The following code is by no means good, just something simple and complete I would expect to work:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using a generic error System.Windows.Forms;namespace BitmapOutput{ public partial class Form1 : Form { ///