Net Bitmap Save Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss
A Generic Error Occurred In Gdi C# Image Save
the workings and policies of this site About Us Learn more about a generic error occurred in gdi in c# windows application Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow
A Generic Error Occurred In Gdi Image Save Vb Net
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each how to solve a generic error occurred in gdi+ 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 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 a generic error occurred in gdi+. asp.net c# 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 the resized bitmap oGraphics.DrawImage(originalBMP, 0, 0, thumbWidth, thumbHeight); Bitmap newBitmap = new Bitmap(thumbBMP); thumbBMP.Dispose(); thumbBMP = null; // Save the new grap
> .NET Framework Class Libraries Question 0 Sign in to vote Hello All,I was just going to
A Generic Error Occurred In Gdi At System Drawing Image Save In C#
play around by generating some bitmaps programatically.I started off with this c# picturebox image save a generic error occurred in gdi+ simple example, expecting everything to go smoothly, but have run into a strange error.The following code is
A Generic Error Occurred In Gdi+ Windows 7
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 : http://stackoverflow.com/questions/15862810/a-generic-error-occured-in-gdi-in-bitmap-save-method Form { ///
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post http://www.codeproject.com/Questions/52709/C-Bitmap-Save-Generic-GDI-Error your Blog quick answersQ&A Ask a Question View Unanswered Questions http://weblogs.asp.net/anasghanem/solving-quot-a-generic-error-occurred-in-gdi-quot-exception View All Questions... Linux questions C# questions ASP.NET questions SQL questions fabric 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 / a generic WTL / STL Managed C++/CLI 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 a generic error 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 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 C# Bitmap Save Generic GDI+ Error Rate this: Please Sign up or sign in to vote. See more: C# GDI This code is giving me problems: private void SaveBMP(Bitmap bmp)
{
bmp.Save(_project.MapFilePath);
} This line throws a generic GDI+ error. bmp.Save(_project.MapFilePath); Any ideas? quote: It means that the file path points to an image that has already been opened in GDI+. You need to be careful to close your images when you are done with them. There's tons of info on this on
have a write permission on some directory. For example, if you are trying to save the Image from the memory stream to the file system , you may get that error. I also faced that error when I was using Infragistics charts control , the control was trying to create a temporary chart in ChartImages folder and my application was not given the write permission. Please if you are using XP, make sure to add write permission for the aspnet account on that folder. If you are using windows server (2003,2008) or Vista, make sure that add write permission for the Network service account. Hope it help some one. 23 Comments Na, _one_ of the possible errors could be the one, you described. The "Generic error" in fact is used in certain scenarios. It means "we were to lazy to write better error return code". This really sucks. Uwe - Saturday, February 28, 2009 8:44:55 PM Well, at least that's based on my experience and on the problems i faced. I know that there is many other causes of that problem,but that's what i know until this time. anas - Saturday, February 28, 2009 8:57:28 PM I think it's the most common error so permissions should always be checked first. SGWellens - Saturday, February 28, 2009 9:18:12 PM It might not be that you don't have write permissions, but a sharing violation might be in effect. Common scenario that this happens: 1) Read an image into a Bitmap object 2) Manipulate the bitmap 3) Wanting to write back the bitmap to overwrite the original image file you read in step 1. This can happen because the Bitmap implementation seems to be as lazy as possible. It can choose the just remember the path that was the source of the image bits (or even a handle to the opened file they came from). This then means your software has the original image file open, causing this problem when you try to overwrite it in step three. To work around this use some simple code in an intermediate step (let's say 1a) that creates a new, blank Bitmap object with the same width/height/colordepth as the image you read. Then, get a Graphics object for the blank image and draw (BitBlt, basically) the loaded image onto the blank image. Then, dispose the loaded image. This gets you a Bitmap object that contains the content of the loaded image actually stored in memory, without any link to the original image file. Then, work on the Bitmap the way you like and you can easily save it back over the original file in step 3 without sharing violations. (If you have write permissions, of course. ;-)) peSHIr - Sunday, March 1, 2009 10:54:34 AM Hi peSHIr, Thanks for infor