C Bitmap Save 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 a generic error occurred in gdi c# image save workings and policies of this site About Us Learn more about Stack a generic error occurred in gdi image save vb net Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
A Generic Error Occurred In Gdi In C# Windows Application
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. Join
How To Solve A Generic Error Occurred In Gdi+
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 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: system.runtime.interopservices.externalexception (0x80004005): a generic error occurred in gdi+. 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 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
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 more
A Generic Error Occurred In Gdi+. Asp.net C#
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users c# picturebox image save a generic error occurred in gdi+ 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+ windows 7 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 3 Having a code that works for ages when loading http://stackoverflow.com/questions/5813633/a-generic-error-occurs-at-gdi-at-bitmap-save-after-using-savefiledialog 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 pixels in size and http://stackoverflow.com/questions/15571022/how-to-find-reason-for-generic-gdi-error-when-saving-an-image 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.5k25100159 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 original image, the error disappeared. I'm assuming
> .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, expecting everything to go smoothly, a generic 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 System.Windows.Forms;namespace BitmapOutput{ public partial class Form1 : a generic error Form { ///