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 workings and a generic error occurred in gdi bitmap save c# policies of this site About Us Learn more about Stack Overflow the a generic error occurred in gdi c# image save company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users a generic error occurred in gdi in c# windows application 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 takes
A Generic Error Occurred In Gdi When Saving Image
a minute: Sign up A generic error occurred in GDI+ up vote 12 down vote favorite 1 I loaded an image into a Picture Box using: picturebox1.Image = Image.FromFile() and I save it by using: Bitmap bm = new Bitmap(pictureBox1.Image); bm.Save(FileName, ImageFormat.Bmp); It works perfectly fine when creating a new file, but when I try to replace the existing image, I get a generic error occurred in gdi+ save thrown the following runtime error: A generic error occurred in GDI+ So what can I do to solve this problem?? c# bitmap gdi+ share|improve this question edited May 21 '14 at 8:26 Vito Gentile 5,04732765 asked Aug 18 '11 at 9:55 Lakshani 68126 add a comment| 7 Answers 7 active oldest votes up vote 7 down vote accepted That because the image file is used by your picturebox1.Image, try to save it to different file path instead: picturebox1.Image = Image.FromFile(FileName); Bitmap bm = new Bitmap(pictureBox1.Image); bm.Save(@"New File Name", ImageFormat.Bmp); Edit: You could also add a copy from the image at the first place like: picturebox1.Image = new Bitmap(Image.FromFile(FileName)); Bitmap bm = new Bitmap(pictureBox1.Image); bm.Save(FileName, ImageFormat.Bmp);//no error will occurs here. share|improve this answer edited Mar 11 '14 at 11:24 answered Aug 18 '11 at 9:58 Jalal Said 11.3k22853 Thanks. If I want to replace, can't I do that? –Lakshani Aug 18 '11 at 9:59 If you want to replace, you should remove the image first from the pictureBox.Image then replace, and then re-add it to the pictureBox.Image, you c
here for a quick overview of the site Help Center Detailed answers to any questions you might have a generic error occurred in gdi+ at system drawing image save Meta Discuss the workings and policies of this site About Us
A Generic Error Occurred In Gdi Act
Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with
A Generic Error Occurred In Gdi Asp Net
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, just http://stackoverflow.com/questions/7105561/a-generic-error-occurred-in-gdi like you, helping each other. Join them; it only takes a minute: Sign up “A generic error occurred in GDI+” when attempting to use Image.Save up vote 4 down vote favorite 1 I am developing an Outlook 2010 Add-In, and am loading an image from a serialized XML file. The image loads fine, and am able to http://stackoverflow.com/questions/14866603/a-generic-error-occurred-in-gdi-when-attempting-to-use-image-save assign it to a pictureBox object on a Winform no problem. The object is saved in [XmlIgnore] public Bitmap Image { get { return this.templateImage; } set { this.templateImage = value; } } When, I attempt to save the physical file onto the harddisk however, I am doing: string filePath = Path.Combine(dirPath, item.Id + ".jpg"); try { item.Image.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); } catch (Exception e) { Debug.WriteLine("DEBUG::LoadImages()::Error attempting to create image::" + e.Message); } and am getting an A generic error occurred in GDI+. I've checked the write permissions on the folder, and it does have write permissions. I'm unsure what is wrong here. I've also changed the ImageFormat to bmp and png and so forth to see if it was a conversion problem... but it isn't. Would anybody suggest something to try? c# .net gdi+ share|improve this question asked Feb 14 '13 at 1:56 Magnum 98721031 2 There are so many possible reasons for this error.. its very frustrating. Some things to try: 1) Write to
to: public void SaveImage() { byte[] byteArray = null; // Put the bytes https://www.roelvanlisdonk.nl/2011/12/30/solving-a-generic-error-occurred-in-gdi-in-c/ of the image here.... Image result = null; ImageFormat format = ImageFormat.Png; using (MemoryStream ms = new MemoryStream(byteArray)) { result = Image.FromStream(ms); } using (Image imageToExport https://social.msdn.microsoft.com/Forums/vstudio/en-US/b15357f1-ad9d-4c80-9ec1-92c786cca4e6/bitmapsave-a-generic-error-occurred-in-gdi?forum=netfxbcl = result) { string filePath = string.Format(@"C:\Temp\Myfile.{0}", format.ToString()); imageToExport.Save(filePath, format); } } This resulted in the error: "A generic error occurred in GDI+." The a generic error was resolved, after changing the code to: public void SaveImage() { byte[] byteArray = null; // Put the bytes of the image here.... Image result = null; ImageFormat format = ImageFormat.Png; result = new Bitmap(new MemoryStream(byteArray)); using (Image imageToExport = result) { string filePath = string.Format(@"C:\Temp\Myfile.{0}", format.ToString()); imageToExport.Save(filePath, format); a generic error } }
I found the solution at: http://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream Categorized in Uncategorized Tagged with C# View all 4 comments Leave a Reply Cancel reply Your email address will not be published. Required fields are marked *Comment Name * Email * Website 4 comments Dino says: January 13, 2012 at 17:57 Hello I find on web that you have similar error like I get now and I don't know how to resole. In my C#.NET application I catch webcam picture in pictureBox and try to save on disk with SaveFileDialog, but I get always the same error "A generic error occurred in GDI+". Code is blow, if you can help… ======================= SaveFileDialog sfd = new SaveFileDialog(); sfd.InitialDirectory = @"slike"; sfd.Filter = "*.jpg|*.jpg"; sfd.Title = "Spremi sliku kao…"; sfd.FilterIndex = 1; if (sfd.ShowDialog() == DialogResult.OK) { try { using (Bitmap bitmap = new Bitmap(pictureBox1.Image)) { bitmap.Save(sfd.FileName, ImageFormat.Jpeg); sfd.Dispose();//To Do…. isprobaj bitmap.Dispose();//To Do…> .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, 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 : Form { ///