【转】c#读取图像保存到数据库中(数据库保存图片)
2015-02-04 14:55
369 查看
转自:http://www.jb51.net/article/45807.htm
注: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;
}
注: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;
}
相关文章推荐
- c#读取图像保存到数据库中(数据库保存图片)
- C# 保存PictureBox中的图片到数据库,并从数据库读取图片显示到PictrueBox,解决报错 “无效参数”
- 图片保存到数据库以及C#读取图片
- C#保存图片到数据库,读取图片显示
- 图片保存到数据库和从数据库读取图片并显示(c#)
- C#保存图片到数据库,读取图片显示
- c# 图片保存到数据库和从数据库读取图片并显示
- C#将图片保存到数据库字段并反向读取
- 用C#编程从数据库中读取图片数据导进Excel文件的方法(如何从数据库中读取保存的文件,直接打开,中间不保存到本地)
- C#保存图片到数据库并读取显示图片的方法
- C#保存图片到数据库并读取显示图片的方法
- C# 图片保存到数据库和从数据库读取图片并显示
- 图片保存到数据库和从数据库读取图片并显示(c#)
- 用C#编程从数据库中读取图片数据导进Excel文件的方法(如何从数据库中读取保存的文件,直接打开,中间不保存到本地)
- 图片保存到数据库和从数据库读取图片并显示(c#)
- 如何读取保存在数据库中的图片显示在DataGrid中
- asp.net ,c# 保存图片入数据库
- [转]C#将文件保存到数据库中或者从数据库中读取文件
- web中,如何读取Word内容(包含表格,但不包含图片)并且显示在页面中或保存进数据库中
- Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示