0

I have already red some answers here on stackoverflow regarding this, but i just can't figure out which part am i disposing too fast:

A generic error occurred in GDI+, JPEG Image to MemoryStream

Image.Save(..) throws a GDI+ exception because the memory stream is closed

The exception is thrown on this line:

image.Save(path, imageCodecInfo, encoderParameters);
Community
  • 1
  • 1
Jo Smo
  • 6,923
  • 9
  • 47
  • 67
  • which line does the error ocur? –  Oct 25 '15 at 15:58
  • @Micky this one: `image.Save(path, imageCodecInfo, encoderParameters);` – Jo Smo Oct 25 '15 at 20:32
  • 2
    You'll get this exception whenever the codec has trouble writing the file. A good debugging statement to add is System.IO.File.WriteAllText(path, "test") before the Save() call, it verifies the basic ability to create the file. You'll now get a good exception that tells you what you did wrong. Use MapPath(). – Hans Passant Oct 26 '15 at 11:23
  • @HansPassant thank you for saving me. I got this: `Could not find a part of the path 'C:\Program Files (x86)\IIS Express\~\Content\Images\23.jpg'.` The path was not the one i thought it would be. So that explains it all i think. Too bad that i didn't think of trying to write a file before myself. I feel stupid. :D – Jo Smo Oct 26 '15 at 11:32

0 Answers0