Note that there are some explanatory texts on larger screens.

plurals
  1. POImage.Save() throws ExternalException on Image loaded from Stream (Image.FromStream())
    text
    copied!<p>I'm tracking down a pesky problem and I've narrowed down the problem down and realized it only happens when I'm dealing with an Image instance returned by Image.FromStream(). I have a utility method that returns an Image instance from a file using a Stream so I don't have the file handle left open. Here is that utility method (nothing special):</p> <pre><code>public static Image ImageFromFileReleaseHandle(string filename) { using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { return Image.FromStream(fs); } } </code></pre> <p>When I try to save an Image loaded from the above method I'm getting an InteropServices.ExternalException "A generic error occurred in GDI+.". The following code example will demonstrate this:</p> <pre><code>private void button6_Click(object sender, EventArgs e) { var filename = @"D:\My Documents\My Pictures\2010-03-27 hangover hike.jpg"; // Get an Image instance Image image; using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { image = Image.FromStream(fs); } // Save to a temp file - this is the code that throws the exception image.Save(Path.GetTempFileName()); } </code></pre> <p>If I load the image using Image.FromFile() I can save no problem:</p> <pre><code>private void button6_Click(object sender, EventArgs e) { var filename = @"D:\My Documents\My Pictures\2010-03-27 hangover hike.jpg"; // Get an Image instance Image image = Image.FromFile(filename); // Save to a temp file - this is the code that throws the exception image.Save(Path.GetTempFileName()); } </code></pre> <p>I can't think of any additional information that would be helpful. Hopefully my code examples are simple enough that you can clearly see the problem.</p> <p>Thanks, Steve</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload