【发布时间】:2016-05-11 12:31:06
【问题描述】:
在某些情况下,只有我收到此错误。 “参数在 System.Drawing.Bitmap..ctor(Stream stream) 处无效堆栈跟踪”我有点困惑它是如何为某些记录工作的,为什么不为其他记录工作。任何人请指导我找到我的错误将非常有帮助..,
以下是我的代码。,
private void RefreshImage()
{
if (this.dsPatPhoto.dmDoc.Count <= 0) return;
byte[] patImage = null;
byte[] driverLicImage = null;
foreach (CmData.WrCmDoc.DsCmDoc.dmDocRow row in this.dsPatPhoto.dmDoc)
{
if (!row.IsIDDocTypeNull() &&
row.IDDocType == (short)AppCommonCfg.DocType.PatientDriverLicense)
{
if (!row.IsDocImageNull())
driverLicImage = row.DocImage;
}
else
{
if (!row.IsDocImageNull())
patImage = row.DocImage;
}
}
System.IO.MemoryStream stream;
if (patImage != null && patImage.Length > 0)
{
stream = new System.IO.MemoryStream(patImage, true);
this.ucPictureEditPic.Clear();
this.ucPictureEditPic.Image = new System.Drawing.Bitmap(stream);
}
if (driverLicImage != null && driverLicImage.Length > 0)
{
stream = new System.IO.MemoryStream(driverLicImage, true);
this.ucPictureEditDL.Clear();
this.ucPictureEditDL.Image = new System.Drawing.Bitmap(stream); //Error occurs here.
}
}
【问题讨论】:
-
存储在数据集中的图像是有效图像吗?如果构造函数无法弄清楚字节数据的结构,它将无法从字节构造图像。如果您从已知文件加载字节并将其与数据集中的字节进行比较,它们是否匹配?另请参阅Bitmap reference source。
-
@theB-感谢您的回复-但我不确定我的图片是否无效。如果它是一个损坏的图像意味着我能做什么..,有没有办法将它转换成有效的图像。通过代码我们可以使它成为可能吗??
-
从参考源看来,位图类使用 GDI+ 创建图像。有 7 个 GDI 错误会导致构造函数抛出
ArgumentException1) 无效参数,2) 未知图像格式,3) 未找到属性,4) 不支持属性,5-7) 各种字体问题。鉴于问题的描述,我愿意消除除#2之外的所有内容。如果将数据集中的数据保存到文件中,是否可以在图像编辑器中打开该文件? (IE - 遇到异常时使用System.IO.File.WriteAllBytes()将字节数组转储到文件中。) -
@theB-sorry for ask you can post a sample code将非常有帮助..
标签: c# bitmap stream bytearray memorystream