我试图将图像保存到MemoryStream
中,但在某些情况下失败。Image.Save崩溃:{“值不能为空。 r n参数名称:编码器”}
下面是代码:
下面的代码成功:
Image img = Bitmap.FromStream(fileStream);
MemoryStream ms = new MemoryStream();
img.Save(ms, img.RawFormat); // This succeeds.
下面的代码失败:
Image img = Bitmap.FromStream(fileStream);
Image thumb = img.GetThumbnailImage(thumbWidth, thumbHeight, null, System.IntPtr.Zero);
MemoryStream ms = new MemoryStream();
thumb.Save(ms, thumb.RawFormat); // This fails.
注意,第二代码段使用图像使用Image.GetThumbnailImage
创建的。
有什么区别?有谁知道它为什么会失败?
将'thumb.Save(ms,thumb.RawFormat)'改为'thumb.Save(ms,thumb.Bmp)'做到了! – agarcian 2012-01-31 03:28:22