首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#打开图片有关问题.

2012-01-22 
C#打开图片问题.....if(dstOther.Tables[0].Rows[0][7]!System.DBNull.Value){this.ImageCount(Byte[])d

C#打开图片问题.....
if(dstOther.Tables[0].Rows[0][7]     !=     System.DBNull.Value     )    
                                                                                                                                              {    
                                                                                                                                                                      this.ImageCount=(Byte[])dstOther.Tables[0].Rows[0][7];    
     
                                                                                                                                                                      if(this.ImageCount!=null)    
                                                                                                                                                                      {    
                                                                                                                                                                                              System.IO.MemoryStream     Ms     =     new     MemoryStream(this.ImageCount);    
     
                                                                                                                                                                                              Ms.Write(this.ImageCount,0,this.ImageCount.Length);    


 
                                                                                                                                                                                              this.img=(Image)Image.FromStream(Ms);    
                                                                                                                                                                                                 
                                                                                                                                                                                              this.picR4.Image=this.img     ;    
                                                                                                                                                                      }    
                                                                                                                                              }    
 
 
上面代码运行到    
this.img=(Image)Image.FromStream(Ms);    
时出错提示说使用了无效参数.

[解决办法]
你的这句
this.img=(Image)Image.FromStream(Ms);

中Ms是图片的流吗?

怎么觉得你没有得到Ms啊,只是声明了一个空的Ms数组.


[解决办法]
注:MyTools.g_PhotoField为数据库表中的图象字段名称
//将图片保存到数据库中
if(this.picPhoto.Image==null)
{
m_DataRow[MyTools.g_PhotoField]=DBNull.Value;
}
else
{
try
{
MemoryStream ms = new MemoryStream ();
picPhoto.Image.Save (ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte [] myData = new Byte [ms.Length ];
ms.Position = 0;
ms.Read (myData,0,Convert.ToInt32 (ms.Length ));
m_DataRow[MyTools.g_PhotoField] = myData;

}
catch(System.Exception ee)
{
MessageBox.Show(ee.Message);
}
}//else

//读取图象
if(this.m_DataRow[MyTools.g_PhotoField]!=DBNull.Value)
{
try
{
Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])m_DataRow[MyTools.g_PhotoField];
MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
this.picPhoto.Image= Image.FromStream(stmBLOBData);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
this.picPhoto.Image= null;
}

热点排行