473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GDI+ Error on Bitmap Save

WB
Hi,

I have a helper class that has a method to resize images. It takes the
virtual path of an image and resize it to a specified dimension like this.

public void ResizeImageTest(string pathImage, int newDimension)
{
string pathImageOnDisk =
System.Web.HttpContext.Current.Server.MapPath(path Image);
System.IO.FileStream fs = new System.IO.FileStream(pathImageOnDisk,
System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite,
System.IO.FileShare.ReadWrite);
Image imageOriginal = Image.FromStream(fs);

using (Bitmap bitmapNewImage = new Bitmap(imageOriginal, newDimension,
newDimension))
{
bitmapNewImage.Save(coreFile.GetPhysicalPath(pathI mage),
imageOriginal.RawFormat);
}
}

When I try to call this method, it will error out in the line of the
"bitmapNewImage.Save" with this:

Exception Details: System.Runtime.InteropServices.ExternalException: A
generic error occurred in GDI+.

However, it works fine if I save to a different file like this:

string pathDummyImageOnDisk =
System.Web.HttpContext.Current.Server.MapPath("/images/dummyPic.jpg");
bitmapNewImage.Save(pathDummyImageOnDisk, imageOriginal.RawFormat);

I have searched the web and found that my solution might be in here:

http://support.microsoft.com/?id=814675

But I don't really understand the steps, such as how to create a new bitmap
"with a pixel format of more than 8 bits-per-pixel (BPP)", how to "use the
Graphics.FromImage() method to obtain a Graphics object for the second
Bitmap" etc.

Any advice?
Thanks,
WB
Dec 16 '05 #1
1 6470
WB

Sorry, there's a typo in the line with "bitmapNewImage.Save". It is actually
like this:

public void ResizeImageTest(string pathImage, int newDimension)
{
string pathImageOnDisk =
System.Web.HttpContext.Current.Server.MapPath(path Image);
System.IO.FileStream fs = new System.IO.FileStream(pathImageOnDisk,
System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite,
System.IO.FileShare.ReadWrite);
Image imageOriginal = Image.FromStream(fs);

using (Bitmap bitmapNewImage = new Bitmap(imageOriginal, newDimension,
newDimension))
{
bitmapNewImage.Save(pathImageOnDisk, imageOriginal.RawFormat);
}
}

Please help.

"WB" wrote:
Hi,

I have a helper class that has a method to resize images. It takes the
virtual path of an image and resize it to a specified dimension like this.

public void ResizeImageTest(string pathImage, int newDimension)
{
string pathImageOnDisk =
System.Web.HttpContext.Current.Server.MapPath(path Image);
System.IO.FileStream fs = new System.IO.FileStream(pathImageOnDisk,
System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite,
System.IO.FileShare.ReadWrite);
Image imageOriginal = Image.FromStream(fs);

using (Bitmap bitmapNewImage = new Bitmap(imageOriginal, newDimension,
newDimension))
{
bitmapNewImage.Save(coreFile.GetPhysicalPath(pathI mage),
imageOriginal.RawFormat);
}
}

When I try to call this method, it will error out in the line of the
"bitmapNewImage.Save" with this:

Exception Details: System.Runtime.InteropServices.ExternalException: A
generic error occurred in GDI+.

However, it works fine if I save to a different file like this:

string pathDummyImageOnDisk =
System.Web.HttpContext.Current.Server.MapPath("/images/dummyPic.jpg");
bitmapNewImage.Save(pathDummyImageOnDisk, imageOriginal.RawFormat);

I have searched the web and found that my solution might be in here:

http://support.microsoft.com/?id=814675

But I don't really understand the steps, such as how to create a new bitmap
"with a pixel format of more than 8 bits-per-pixel (BPP)", how to "use the
Graphics.FromImage() method to obtain a Graphics object for the second
Bitmap" etc.

Any advice?
Thanks,
WB

Dec 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
20
by: Nathan Sokalski | last post by:
I am trying to create graphics with GDI+ that include transparency. However, the transparency never seems to show up, even though my colors have an alpha value of 0. How can I generate a graphic...
1
by: Prasad More | last post by:
Hello, I am trying to write a text on Multi-page TIFF image using C# and .NET GDI+. I have written following code to do this. When I execute this code I get "Invalid Parameter User. at...
9
by: Sharon | last post by:
I'm trying to convert an Image file to a byte array . Later in my code I'm trying to create a new Image from this byte array as a restored Image. But when I try to save the restored Image to a...
5
by: Pohihihi | last post by:
I am getting a generic GDI+ error on following code. Basically it is trying to capture screen image and save in a file. Is there a way to find more details on this error? Thanks for the help. ...
7
by: Philip Wagenaar | last post by:
I use a class to manage tiff's (written by someone else) to splitt multipage tiffs. However, when I run it, it fails, for other people it seems work ok. The method in the class is :public...
2
by: Alphonse Giambrone | last post by:
I am currently reading 'Programming The Web with Visual Basic .NET' and have so far found it to be excellent. Downloaded all the code from Apress and working in chapter 4, I get the error shown...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.