Image.FromStream(ms) 提示参数无效

说明ms有问题,首先确保有读到数据,这种情况是保存到库的时候出错的。

原来你可能是这样写的:

MemoryStream stream = new MemoryStream();
PictureBox1.Image.Save(stream, ImageFormat.Bmp ); //这里出错,原图片格式是JPEG
byte [] bytestream = new byte [ stream.Length ];
stream .Read (bytestream ,0,bytestream .Length );
stream.Flush();

应该为:

MemoryStream stream = new MemoryStream();
PictureBox1.Image.Save(stream,PictureBox1 .Image .RawFormat );
byte[] bytestream = stream.ToArray();
stream.Flush();

原文地址:https://www.cnblogs.com/dachuang/p/9105762.html