Interopservices Externalexception A Generic Error Occurred
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss
A Generic Error Occurred In Gdi C# Image Save
the workings and policies of this site About Us Learn more about system.runtime.interopservices.externalexception (0x80004005): a generic error occurred in gdi+. Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
A Generic Error Occurred In Gdi Bitmap Save C#
Jobs Documentation 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. a generic error occurred in gdi in c# windows application Join them; it only takes a minute: Sign up A generic error occurred in GDI+ at System.Drawing.Image.Save up vote 10 down vote favorite 1 Exception: A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename) Code: byte[] bitmapData = new byte[imageText.Length]; MemoryStream streamBitmap; bitmapData = Convert.FromBase64String(imageText); streamBitmap how to solve a generic error occurred in gdi+ = new MemoryStream(bitmapData); System.Drawing.Image img = Image.FromStream(streamBitmap); img.Save(path); We convert a base64 string into a MemoryStream and then create a System.Drawing.Image (Image.FromStream(streamBitmap)). At the end the image is saved in a temp file. The strange thing is that the problem seems to occur when the activity (number of concurrent users) is high on the web server and the problem is solved temporarily after an IISRESET or an application pool recycle... ==> Garbage collector issue ? I already checked the permission of the TEMP folder... c# asp.net .net image gdi+ share|improve this question edited Mar 28 '14 at 9:46 asked Mar 28 '14 at 8:59 Razor 62021223 add a comment| 3 Answers 3 active oldest votes up vote 9 down vote When you are loading an imagefrom a Stream, You have to keep the stream open for the lifetime of the image, see MSDN Image.FromStream. I think the exception is caused because the memory stream gets closed even before the image gets disposed. You can change your code like this byte[] bitmapData = new byte[i
here for a quick overview of the site Help Center Detailed answers
How To Fix A Generic Error Occurred In Gdi+
to any questions you might have Meta Discuss the workings a generic error occurred in gdi+. asp.net c# and policies of this site About Us Learn more about Stack Overflow the company Business
A Generic Error Occurred In Gdi At System Drawing Image Save In C#
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the http://stackoverflow.com/questions/22708150/a-generic-error-occurred-in-gdi-at-system-drawing-image-save 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 System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+ up vote 1 down vote favorite I have a code that rotate image in my asp.net http://stackoverflow.com/questions/30678561/system-runtime-interopservices-externalexception-a-generic-error-occurred-in-gd C# application this is my code: protected void ImgBtn180_Click(object sender, ImageClickEventArgs e) { try { string vImageName = LblFarmId.Text; string vPath = "~/attachments/survey/" + vImageName + ".jpg"; Image1.ImageUrl = vPath; //get the path to the image string path = Server.MapPath(vPath); //create an image object from the image in that path System.Drawing.Image img = System.Drawing.Image.FromFile(path); //rotate the image img.RotateFlip(RotateFlipType.Rotate180FlipXY); //save the image out to the file img.Save(path); //release image file img.Dispose(); Random rnd = new Random(); Image1.ImageUrl = vPath + "?" + rnd; } catch (Exception ee) { LblCatchError.Text = ee.ToString(); } } when I run it on the server, I'm getting sometimes the following error System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename) and sometimes the following error System.OutOfMemoryException: Out of memory. at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement) at System.Drawing.Image.FromFile(String filename) I read all ar
error occurred in GDI+. Visual Studio Languages , .NET Framework > Visual C# Question 0 Sign in to vote I'm converting a byte array to an image https://social.msdn.microsoft.com/Forums/vstudio/en-US/437dafaf-ebad-4f38-b1d5-ab9d15949aa8/systemruntimeinteropservicesexternalexception-a-generic-error-occurred-in-gdi?forum=csharpgeneral and then save it to disk: MemoryStream ms = new MemoryStream(mybytearray); Bitmap x = new Bitmap(Image.FromStream(ms, true, true), 100, 100); x.Save(@"c:\image.png"); When the method is called http://www.codeproject.com/Questions/206755/A-generic-error-occurred-in-GDIplus multiple times I get the following exception: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) a generic at System.Drawing.Image.Save(String filename) Edited by FAndrei Friday, February 03, 2012 10:19 PM Friday, February 03, 2012 10:19 PM Reply | Quote Answers 1 Sign in to vote Hi sir, I have just modified your code a bit by including it in functions... I clicked on the button 101 times and no error.... working perfect Please try this one a generic error : using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public byte[] imageToByteArray(System.Drawing.Image imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return ms.ToArray(); } public Image byteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Bitmap returnImage = new Bitmap(Image.FromStream(ms,true,true),100,100); returnImage.Save(@"C:\Data\Rehan1.png"); return returnImage; } private void button1_Click(object sender, EventArgs e) { try { byte[] byt = imageToByteArray(Image.FromFile(@"C:\Data\Rehan.jpg")); pictureBox1.Image = byteArrayToImage(byt); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } As you have included memory stream objects in the function, they have local scope so disposing will not be an issue.. with your code after you complete your processing you need to dispose all memory objects and bytes so this is a good alternative to use it in functions. Please mark as answer if this post helps you and unpropose it as answer if it does not help you. Thanks Rehan Bharucha - The Tech Robot MC
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ A generic error occurred in GDI+ Rate this: Please Sign up or sign in to vote. See more: C# I have looked around but nothing seemed to really match my problem. I am trying to save a picture from a direct link. Either as a gif or png depending on what is needed. Every time I try to save the file I get said error. public void SaveImage(String ID, string pokemonName, bool isShiny, ImageFormat imageFormat, bool isSprite = false) { Directory.CreateDirectory(@"C:\Users\Cardon\Documents\Pokemon\" + ID + " - " + pokemonName); var tmpImageFormat = (imageFormat == ImageFormat.Gif) ? "gif" : "png"; var url = (isSprite) ? "http://www.serebii.net/pokedex-bw/icon/" + ID + "." + tmpImageFormat : (isShiny