GDI+中发生一般性错误

转帖|其它|编辑:郝浩|2008-09-22 14:35:12.000|阅读 2435 次

概述:GDI+中发生一般性错误

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

有这么一段将从数据库读出的图片的字节数组转换为图片的程序:

 public static Image byteArrayToImage(byte[] byteArrayIn)
        {
            try
            {
                if (byteArrayIn.Length > 0)
                {
                    using (MemoryStream ms = new MemoryStream(byteArrayIn))
                    {                                  
                        Image returnImage = Image.FromStream(ms);
                        ms.Close();
                        return returnImage;
                    }
                }
                return null;
            }
           catch
           {}
        }
外部是这样调用的 :

            try
            {
                pbox_图片1.Image = ImageByteConvert.byteArrayToImage((byte[])(row_道班房屋["图片1"]));
            }
            catch
            {
            }
            pbox_图片2.Image = null;
            try
            {
                pbox_图片2.Image = ImageByteConvert.byteArrayToImage((byte[])(row_道班房屋["图片2"]));
            }
            catch
            {
            }
数据库中有两条记录,每条记录有2张图片。使用第一条记录时没有任何问题,但是使用第二条记录时,如果执行

            try
            {
                pbox_图片1.Image = ImageByteConvert.byteArrayToImage((byte[])(row_道班房屋["图片1"]));
            }
            catch
            {
            }
就会出现这样的情况:

以上代码的异常捕获都没有捕捉到异常,但是当

Form_Load(object sender, EventArgs e)
{
   ...
   ...
   ...
}
执行完毕后就会引发“GDI+中发生一般性错误”

然而不执行

            try
            {
                pbox_图片1.Image = ImageByteConvert.byteArrayToImage((byte[])(row_道班房屋["图片1"]));
            }
            catch
            {
            }
,单独执行

pbox_图片2.Image = null;
            try
            {
                pbox_图片2.Image = ImageByteConvert.byteArrayToImage((byte[])(row_道班房屋["图片2"]));
            }
            catch
            {
            }


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:DIY部落

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP