看见一篇文章,说可以实现Bitmap byte[] Stream 文件相互转换,代码如下
public static Bitmap BytesToBitmap(byte[] Bytes)
{
MemoryStream stream = null;
try
{
stream = new MemoryStream(Bytes);
return new Bitmap((Image)new Bitmap(stream));
}
catch (ArgumentNullException ex)
{
throw ex;
}
catch (ArgumentException ex)
{
throw ex;
}
finally
{
stream.Close();
}
}
代码敲入之后,编译正常,报错,参数无效
追究原因,
stream
不包含图像数据,或者为 null
。
- 或 - stream
包含一个 PNG 图像文件,其一维大于 65,535 像素。
就是所如果新建的一个stream,里面肯定是没有图像数据的,自然就报了输入参数无效了。