首页 > 其他 > 详细

C#图像读取

时间:2014-01-21 01:28:15      阅读:362      评论:0      收藏:0      [点我收藏+]
注: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#图像读取

原文:http://blog.csdn.net/jianxia_wzx/article/details/18310399

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!