【问题标题】:C# Bitmap Image - Exception : Parameter is not validC#位图图像 - 异常:参数无效
【发布时间】:2017-09-08 09:17:52
【问题描述】:

我尝试与Image 合作。它运行良好,但有时我得到“参数无效”异常。我不知道为什么会出现这个问题,请帮助我:

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();
        }
    }
}

当我检查它时,我意识到abc == null 的值,它导致了这个异常。我该如何解决这种情况?

【问题讨论】:

  • 这个错误发生在哪一行?
  • @Jerodev : 它已经在代码中注释了
  • 可能是imgBox.Image的大小问题
  • 您是否能够使用某些始终触发此异常的特定图像可靠地重现它?
  • @Rahul 为什么 imgBox.Image 的大小会影响这种情况?

标签: c# image exception bitmap memorystream


【解决方案1】:

问题可能出在方法上

Image.FromStream(stream)

对无效图片数据和 null 抛出 ArgumentException

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多