Bmp Save 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
C Bmp Save
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users android bmp save Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping a generic error occurred in gdi c# image save each other. Join them; it only takes a minute: Sign up A Generic error occurs at GDI+ at Bitmap.Save() after using SaveFileDialog up vote 20 down vote favorite 3 I use the following code block with some more
How To Solve A Generic Error Occurred In Gdi+
code inside the using block: using (System.Drawing.Bitmap tempImg = (System.Drawing.Bitmap)tempObj.GetData(System.Windows.Forms.DataFormats.Bitmap)) { // ... tempImg.Save("..\\..\\testdata\\tempImg.bmp", ImageFormat.Bmp); // ... } But I still get the error: A Generic Error occured at GDI+ only after I make some action which is not related to the code inside the using block. In other times this works well. Also the tempImg.bmp is a temporary file, so I delete the tempImg.bmp within the using block itself. Since the tempImg is inside the
A Generic Error Occurred In Gdi In C# Windows Application
using and this it's disposed, I think the locking problem should be solved. Can someone please let me know what is the mistake in this code? Edit: System.Drawing.Image to System.Drawing.Bitmap as the type of tempImg. Edit: I have identified I get this error only after SaveFileDialog is created and user clicks on 'Save'. c# bitmap save savefiledialog share|improve this question edited May 5 '11 at 9:32 asked Apr 28 '11 at 4:28 Dulini Atapattu 1,73642442 Why is tempImg Image and your cast Bitmap ? –V4Vendetta Apr 28 '11 at 4:33 Sorry, it should be corrected as SYstem.Drawing.Bitmap... thanks for comment –Dulini Atapattu Apr 28 '11 at 4:51 only after I make some action which is not related to the code does this involve reading/saving some other image ? –V4Vendetta Apr 28 '11 at 5:44 No, it only create an avi file using the Bitmap objects obtained from tempImg though a stream within the using block itselft and tempImg.bmp is deleted each time after obtaining the bitmap object. –Dulini Atapattu Apr 28 '11 at 6:31 So that might be the problem since its already in use by the process, post that code so it would be more relevant –V4Vendetta Apr 28 '11 at 6:36 add a comment| 10 Answers 10 active oldest votes up vote 31 down vote acce
here for a quick overview of the site Help Center Detailed answers to any questions you a generic error occurred in gdi+. asp.net c# might have Meta Discuss the workings and policies of this site
C# Picturebox Image Save A Generic Error Occurred In Gdi+
About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or a generic error occurred in gdi at system drawing image save in c# posting ads 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 http://stackoverflow.com/questions/5813633/a-generic-error-occurs-at-gdi-at-bitmap-save-after-using-savefiledialog 4.7 million programmers, 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 http://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream been unable to find 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.Conve
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 http://www.codeproject.com/Questions/283361/A-generic-error-occurred-in-GDIplus 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 a generic 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 a generic error 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# C#4.0 I want to save an image to the same file it was created from. Platform: C#.Net. Bitmap varBmp = (Bitmap)Bitmap.FromFile(@"E:\a.jpg"); //do something varBmp.Save(@"E:\a.jpg"); It shows the following error: A generic error occurred in GDI+. How to solve the problem? How to get the handle of the varBmp image? Thanks in advance. Posted 13-Nov-11 23:24pm akul123749 Updated 13-Nov-11 23:26pm v2 Add a Solution 4 solutions Top Rated Most Recent Rate this: Please Sign up or sign in to vote. Solution 3 Accept Solution Reject Solution There is a fundamental problem here: Bitmap.FromFile holds a lock on the file until the Bitmap object has been disposed. This means the file is in use when you try to write it, and GDI throw