Bitmap Save Png Generic Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have generic error occurred in gdi+ bitmap save Meta Discuss the workings and policies of this site About Us a generic error occurred in gdi bitmap save c# Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads android bitmap save to png with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, gdiplus bitmap save png just like you, helping each other. Join them; it 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
A Generic Error Occurred In Gdi C# Image Save
an answer to my problem as my scenario doesn't fit. An exception gets 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
here for a quick overview of the site Help Center
How To Solve A Generic Error Occurred In Gdi+
Detailed answers to any questions you might have Meta Discuss a generic error occurred in gdi in c# windows application the workings and policies of this site About Us Learn more about Stack Overflow the a generic error occurred in gdi+. asp.net c# company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss http://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream 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 Saving Bitmap leads to Generic GDI+ error up vote 3 down vote favorite I've been searching around for a http://stackoverflow.com/questions/6741488/saving-bitmap-leads-to-generic-gdi-error solution to this but haven't really found one. Here is some patchwork code that I've been playing with trying to get this working but no success. private Image GetAlbumArt(String url) { byte[] rBytes; Image Testing; HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); WebResponse myResponse = myRequest.GetResponse(); Stream rStream = myResponse.GetResponseStream(); using (BinaryReader br = new BinaryReader(rStream)) { rBytes = br.ReadBytes(1000000); br.Close(); } myResponse.Close(); using (MemoryStream imageStream = new MemoryStream(rBytes, 0, rBytes.Length)) { imageStream.Write(rBytes, 0, rBytes.Length); Testing = Image.FromStream(imageStream, true); Testing.Save("temp.jpg"); //Error here! } return Testing; } I would actually rather not save the bitmap and just return the bitmap to the parent function, but that didnt work either. (cannot close the memory stream if you want to use the bitmap) The really strange thing is that this works fine if i give it a different jpg url. Doesnt work: http://2.images.napster.com/mp3s/2492/resources/207/116/files/207116316.jpg works: http://3.images.napster.com/mp3s/2256/resources/301/404/files/301404546.jpg c# .net gdi+ share|improve th
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/Advanced ASP.NET/System.Drawing/GDI+/Error in saving Image-A generic error occurred http://forums.asp.net/t/1273771.aspx?Error+in+saving+Image+A+generic+error+occurred+in+GDI+ in GDI+. Error in saving Image-A generic error occurred in http://www.hanselman.com/blog/TheWeeklySourceCode50ALittleOnAGenericErrorOccurredInGDIAndTroubleGeneratingImagesOnWithASPNET.aspx GDI+. RSS 14 replies Last post Jul 26, 2010 07:41 AM by rohitmahadik ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply jeenajos Member 24 Points generic error 144 Posts Error in saving Image-A generic error occurred in GDI+. Jun 11, 2008 03:59 AM|jeenajos|LINK hi all, Im saving a barcode in server.mappath.But its giving an error as A generic error occurred in GDI+. Im trying to save it as Bmp format. Can anyone say why this error generic error occurred has come? Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea) Dim ms2 As MemoryStream = New MemoryStream imgBarcode.Save(ms2, System.Drawing.Imaging.ImageFormat.Bmp) Dim arr2(ms2.Length) As Byte ms2.Write(arr2, 0, arr2.Length) imgBarcode.Save(Server.MapPath("~\Barcode\Data\") & all & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp) //Error is here.Cant Save Image GDI+ Regards, Jeen Reply Bilal_Salih Member 80 Points 34 Posts Re: Error in saving Image-A generic error occurred in GDI+. Jun 11, 2008 04:54 AM|Bilal_Salih|LINK Hi all, Check write permissionof the folder you are trying to write your imageon it. I hope this helps. Reply jeenajos Member 24 Points 144 Posts Re: Error in saving Image-A generic error occurred in GDI+. Jun 11, 2008 05:04 AM|jeenajos|LINK Everything is correct.The thing is that i cant save the image in folder. Wen it reaches the statement, it goes straight to catch message and displays the error. Regards, Jeen Reply Bilal_Salih Member 80 Poi
ASP.NET|Source Code Sponsored By I got a nice little Yellow Screen of Death (YSOD) error on some code running under IIS that worked fine when running on the VS Developer Web Server. The error was "A generic error occurred in GDI+" and you know that if an error is generic, it's sure in the heck not specific. My little application takes an overhead map that's stored in a local file, does some calculations from user input and draws an X on the map, then returns the resulting dynamically generated image. There's basically three ways to do images on the server side. Use Native APIs and Interop, which only works in full trust, use System.Drawing, which "isn't supported" or use WPF on the server side, which also, ahem, isn't officially supported. I'm still trying to figure out why, but just to be clear, I used System.Drawing in extremely high traffic sites with no problems. As long as paid close attention to my unmanaged resources, I have never had a problem. I've heard anecdotally of people having trouble with GDI+ (System.Drawing) and switching over to WPF and having no problem with that. As with all things, test what you're doing. There's even some ASP.NET Controls on CodePlex that might help. Now this post can't answer ALL reasons you're getting "a generic error occurred in GDI+" but it can answer mine. In my particular case (and I think this is the most common mistake) I was saving the composited image as a PNG. First, I'll show you a little chunk of a code from 5 years ago that took two images and built a single image from them. public class SomeCheckImageHandler : IHttpHandler{ //some stuff snipped public SomeCheckImageHandler(){} public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpg"; //some stuff snipped GetCheckImageRequest req = new GetCheckImageRequest(); //some stuff snipped, get the params from the Q