[英]C# Bitmap Image - Exception : Parameter is not valid
I try to work with Image
. 我尝试使用
Image
。 It worked well but sometimes I got “Parameter is not valid” exception. 它运行良好,但有时出现“参数无效”异常。 I don't know why that problem occurs, please help me:
我不知道为什么会出现此问题,请帮助我:
byte[] img = (byte[])PatientData.Rows[index - 1]["Anh"];
MemoryStream ms = new MemoryStream(img);
imgBox.Image.Dispose();
imgBox.Image = Image.FromStream(ms);
using (Bitmap abc = new Bitmap(imgBox.Image)) //Parameter is not valid (Sometimes)
{
using (Image<Gray, byte> xyz = new Image<Gray, byte>(abc))
{
if(Global.xrayPic != null)
{
Global.xrayPic.Dispose();
Global.xrayPic = xyz.Clone();
}
}
}
And when I checked it, I realize that the value of abc
== null and it leads to this exception. 当我检查它时,我意识到
abc
== null的值并导致此异常。 How can I solve this situation? 我该如何解决这种情况?
The problem could be that the method 问题可能是该方法
Image.FromStream(stream) Image.FromStream(流)
throws an ArgumentException on invalid picture data and null. 对无效的图片数据抛出ArgumentException ,并且返回null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.