Externalexception A Generic Error
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 this site About Us Learn more about Stack Overflow the company Business Learn
A Generic Error Occurred In Gdi Bitmap Save C#
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags a generic error occurred in gdi c# image save Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, system.runtime.interopservices.externalexception (0x80004005): a generic error occurred in gdi+. helping each other. Join them; it only takes a minute: Sign up How to find reason for Generic GDI+ error when saving an image? up vote 7 down vote favorite 4 Having a code that works for
A Generic Error Occurred In Gdi In C# Windows Application
ages when loading and storing images, I discovered that I have one single image that breaks this code: const string i1Path = @"c:\my\i1.jpg"; const string i2Path = @"c:\my\i2.jpg"; var i = Image.FromFile(i1Path); i.Save(i2Path, ImageFormat.Jpeg); The exception is: System.Runtime.InteropServices.ExternalException occurred 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 ... As far as I can see, there is nothing special about the image. It is approx 250
How To Solve A Generic Error Occurred In Gdi+
pixels in size and can be opened in e.g. Windows Image Viewer or Paint.NET: (Since the image above, after being uploaded to Stack Overflow does not produce the error anymore, I've put the original image here) What I discovered is that upon calling the Save method, the destination image file is being created with zero bytes. I am really clueless on what causes the error. My questions: Can you think of any special thing that would hinder .NET from saving the image? Is there any way (beside panicing) to narrow down these kind of errors? c# .net image gdi+ system.drawing share|improve this question edited Mar 22 '13 at 13:52 asked Mar 22 '13 at 13:02 Uwe Keim 22.6k25100159 MSDN says a Bitmap loaded from a Stream requires the Stream to remain in existence as long as the Bitmap exists. –Jesse Chisholm Nov 11 '15 at 0:14 add a comment| 6 Answers 6 active oldest votes up vote 17 down vote accepted While I still did not find out the reason what exactly caused the error when saving the image, I found a workaround to apply: const string i1Path = @"c:\my\i1.jpg"; const string i2Path = @"c:\my\i2.jpg"; var i = Image.FromFile(i1Path); var i2 = new Bitmap(i); i2.Save(i2Path, ImageFormat.Jpeg); I.e. by copying the image internally into a Bitmap instance and saving this image instead of the origin
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and how to fix a generic error occurred in gdi+ policies of this site About Us Learn more about Stack Overflow the
System.runtime.interopservices.externalexception: A Generic Error Occurred In Gdi+.
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags a generic error occurred in gdi+. asp.net c# 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 only http://stackoverflow.com/questions/15571022/how-to-find-reason-for-generic-gdi-error-when-saving-an-image takes a minute: Sign up ExternalException: A generic error occurred in GDI+ up vote 2 down vote favorite 1 I am using Selenium WebDriver in C# and I am trying to dynamically create a folder and save screenshots of failing tests to it. Here I am running the group of test cases (Test Suite of 66 test cases). After running the http://stackoverflow.com/questions/38903692/externalexception-a-generic-error-occurred-in-gdi test suite I found few failed tests with GDI+ error and were not captured as a screenshot. But when I run them individually most of the failed cases (GDI+ error) were passing except few. Here is the code for creating a folder: TestExecutionStartTime = DateTime.Now; baseDirectory = AppDomain.CurrentDomain.BaseDirectory + @"\" + ConfigurationManager.AppSettings.GetValues("failedTests")[0]; Browser = ConfigurationManager.AppSettings["WebDriver"]; DirectoryInfo directory = new DirectoryInfo(baseDirectory); DirectoryInfo[] subdirs = directory.GetDirectories(); if (System.IO.Directory.GetDirectories(baseDirectory).Length == 0) { screenshotDirectory = baseDirectory + @"\" + (DateTime.Now.ToString("yyyy_MM_dd_hh_mm") + "_" + Browser); Directory.CreateDirectory(screenshotDirectory); } Here is the code for taking screenshot: public void takeScreenshot(string filename) { string fname = filename + ".jpg"; string screenshot = screenshotDirectory + @"\" + fname; Screenshot ss = ((ITakesScreenshot)WebDriver).GetScreenshot(); byte[] image = ss.AsByteArray; using (MemoryStream ms = new MemoryStream(image)) { Image i = Image.FromStream(ms); i.Save(screenshot); } I assume that the error is at this i.Save(screenshot) call, but I was not able to resolve it. c# selenium webpage-screenshot share|improve this question edited Aug 11 at 21:15 Laurel 3,95981540 asked Aug 11 at 18:27 mitikiri 92 so you just want to capture screenshots when a test fails an
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/Advanced ASP.NET/System.Drawing/GDI+/System.Runtime.InteropServices.ExternalException: A generic error occ... System.Runtime.InteropServices.ExternalException: A generic http://forums.asp.net/t/1353341.aspx?System+Runtime+InteropServices+ExternalException+A+generic+error+occurred+in+GDI+ error occurred in GDI+. [Answered]RSS 9 replies Last post Dec 23, 2013 04:29 AM by Vkas ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply kapilbharat Member 50 Points 152 Posts System.Runtime.InteropServices.ExternalException: A generic error occurred in a generic GDI+. Nov 26, 2008 07:36 AM|kapilbharat|LINK First of all good evenning all. I am facing anerror --System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. its very strange that locallymy code working fine my code is ///