C# Bitmap Save Generic Gdi Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings c# bitmap save a generic error occurred in gdi+ and policies of this site About Us Learn more about Stack c# bitmap.save gdi+ exception Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs c# image save a generic error occurred in gdi+ 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 them;
A Generic Error Occurred In Gdi In C# Windows Application
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 exception "A generic error occurred how to solve a generic error occurred in gdi+ 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 graphic file to the server newBitmap.Save("~/image/thumbs/" + "t" + o
>
C# Picturebox Image Save A Generic Error Occurred In Gdi+
.NET Framework Class Libraries Question 0 Sign in to vote
A Generic Error Occurred In Gdi+ Windows 7
Hello All,I was just going to play around by generating some bitmaps programatically.I started off with http://stackoverflow.com/questions/15862810/a-generic-error-occured-in-gdi-in-bitmap-save-method 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 https://social.msdn.microsoft.com/Forums/vstudio/en-US/b15357f1-ad9d-4c80-9ec1-92c786cca4e6/bitmapsave-a-generic-error-occurred-in-gdi?forum=netfxbcl 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 { ///
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 http://www.codeproject.com/Questions/283361/A-generic-error-occurred-in-GDIplus a Question View Unanswered Questions View All Questions... C# questions Linux questions https://www.roelvanlisdonk.nl/2011/12/30/solving-a-generic-error-occurred-in-gdi-in-c/ 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 a generic 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 Who's Who Most Valuable Professionals The Lounge a generic error 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 Solution Reject Solution There is a fundamental problem here: Bitmap.FromFile holds a lock on the file until th
to: public void SaveImage() { byte[] byteArray = null; // Put the bytes of the image here.... Image result = null; ImageFormat format = ImageFormat.Png; using (MemoryStream ms = new MemoryStream(byteArray)) { result = Image.FromStream(ms); } using (Image 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+." 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()); 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.Dispose();//To Do…. isprobaj bitmap.Dispose();//To Do…. isprobaj } MessageBox.Show("Slika je spremljena! ", "Spremanje slike", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Greška pri spremanju slike: \n" + ex.Message); } finally { sfd.Dispose();// to check….. } } sfd.Dispose();// to check….. button6.Enabled = true; button7.Enabled = false; button8.Enabled = false; button9.Enabled = false; pictureBox1.Image = Image.FromFile("nemaslike.jpg"); this.WebCamCapture.Stop(); textBox1.Focus(); Amine says: May 23, 2013 at 18:38 This problem is mostly occurred for the security reasons. Make sur that you give all permissions to your Folder. punit says: April 4, 2016 at 15:23 How to Put the