Bitmap.save Generic Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you
A Generic Error Occurred In Gdi C# Image Save
might have Meta Discuss the workings and policies of this site a generic error occurred in gdi in c# windows application About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting
How To Solve A Generic Error Occurred In Gdi+
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 4.7 a generic error occurred in gdi+. asp.net c# million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up A Generic error occured in GDI+ in Bitmap.Save method up vote 26 down vote favorite 8 I am working on to upload and same a thumnail copy of that image in a thumbnail forder. I am using a generic error occurred in gdi at system drawing image save in c# following link: http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx but newBMP.Save(directory + "tn_" + filename); is causing exception "A generic error occurred in GDI+." I have tried to give permission on folder, also tried to use a new separate bmp object when saving. Edit: protected void ResizeAndSave(PropBannerImage objPropBannerImage) { // Create a bitmap of the content of the fileUpload control in memory Bitmap originalBMP = new Bitmap(fuImage.FileContent); // Calculate the new image dimensions int origWidth = originalBMP.Width; int origHeight = originalBMP.Height; int sngRatio = origWidth / origHeight; int thumbWidth = 100; int thumbHeight = thumbWidth / sngRatio; int bannerWidth = 100; int bannerHeight = bannerWidth / sngRatio; // Create a new bitmap which will hold the previous resized bitmap Bitmap thumbBMP = new Bitmap(originalBMP, thumbWidth, thumbHeight); Bitmap bannerBMP = new Bitmap(originalBMP, bannerWidth, bannerHeight); // Create a graphic based on the new bitmap Graphics oGraphics = Graphics.FromImage(thumbBMP); // Set the properties for the new graphic file oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic; // Draw the new graphic based on
to: public void SaveImage() { byte[] byteArray = null; // Put the bytes
C# Picturebox Image Save A Generic Error Occurred In Gdi+
of the image here.... Image result = null; ImageFormat format a generic error occurred in gdi+ windows 7 = ImageFormat.Png; using (MemoryStream ms = new MemoryStream(byteArray)) { result = Image.FromStream(ms); } using (Image
System.runtime.interopservices.externalexception (0x80004005): A Generic Error Occurred In Gdi+.
imageToExport = 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+." http://stackoverflow.com/questions/15862810/a-generic-error-occured-in-gdi-in-bitmap-save-method The 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()); https://www.roelvanlisdonk.nl/2011/12/30/solving-a-generic-error-occurred-in-gdi-in-c/ imageToExport.Save(filePath, format); } }
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.DisTips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog http://www.codeproject.com/Questions/283361/A-generic-error-occurred-in-GDIplus 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 http://www.hanselman.com/blog/TheWeeklySourceCode50ALittleOnAGenericErrorOccurredInGDIAndTroubleGeneratingImagesOnWithASPNET.aspx a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI generic error 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 a generic error 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# 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 So
ASP.NET|Source Code Sponsored By I got a nice little Yellow Screen of Death (YSOD) error on some code running under IIS that worked fine when running on the VS Developer Web Server. The error was "A generic error occurred in GDI+" and you know that if an error is generic, it's sure in the heck not specific. My little application takes an overhead map that's stored in a local file, does some calculations from user input and draws an X on the map, then returns the resulting dynamically generated image. There's basically three ways to do images on the server side. Use Native APIs and Interop, which only works in full trust, use System.Drawing, which "isn't supported" or use WPF on the server side, which also, ahem, isn't officially supported. I'm still trying to figure out why, but just to be clear, I used System.Drawing in extremely high traffic sites with no problems. As long as paid close attention to my unmanaged resources, I have never had a problem. I've heard anecdotally of people having trouble with GDI+ (System.Drawing) and switching over to WPF and having no problem with that. As with all things, test what you're doing. There's even some ASP.NET Controls on CodePlex that might help. Now this post can't answer ALL reasons you're getting "a generic error occurred in GDI+" but it can answer mine. In my particular case (and I think this is the most common mistake) I was saving the composited image as a PNG. First, I'll show you a little chunk of a code from 5 years ago that took two images and built a single image from them. public class SomeCheckImageHandler : IHttpHandler{ //some stuff snipped public SomeCheckImageHandler(){} public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/jpg"; //some stuff snipped GetCheckImageRequest req = new GetCheckImageRequest(); //some stuff snipped, get the params from the QueryString GetCheckImageResponse res = banking.GetCheckImage(req); //some stuff snipped if (res.ImageBack != null) { //merge them into one image using(MemoryStream m = new MemoryStream(res.BackImageBytes)) using(Image backImage = System.Drawing.Image.FromStream(m)) using(MemoryStream m2 = new MemoryStream(res.BrontImageBytes)) using(Image frontImage = System.Drawing.Image.FromStream(m2)) using(Bitmap compositeImage = new Bitmap(frontImage.Width,frontImage.Height+backImage.Height)) using(Graphics comp