lundi 30 mars 2015

Image.GetThumbnailImage throws OutOfMemoryException

The following C# 3.5 code throws an exception in GetThumbnailImage:



Image img = null;
Image scaledImg = null;

byte[] imageData = File.ReadAllBytes("11001.jpg");
MemoryStream stream = new MemoryStream(imageData);
img = Image.FromStream(stream);
stream.Close();
stream.Dispose();

scaledImg = img.GetThumbnailImage(64, 64, null, IntPtr.Zero);


The problem is the disposing of the stream. If I remove the Close() and Dispose() statement, everything works fine. Does anyone know why this exception is thrown? Using a callback instead of null as parameter does not change the behavior.


I don't need a solution, I can use new Bitmap(img, new Size(width, height) for scaling. This is probably better and shoud have been used from the beginning.


Aucun commentaire:

Enregistrer un commentaire