Code
//从数据库取图片显示
if (dt.Rows[0]["MPicture"].ToString().Trim()!="")
{
System.IO.MemoryStream myStream;
System.Drawing.Image myImage;
imgdata = (byte[])(dt.Rows[0]["MPicture"]);
myStream = new System.IO.MemoryStream();
foreach (byte a in imgdata)
{
myStream.WriteByte(a);
}
if (imgdata.Length > 0)
{
myImage = System.Drawing.Image.FromStream(myStream);
pic.Image = myImage;//pic:pictureBox
}
}
//将图片保存到数据库
byte[] imgdata = null;
if (pic.Image != null)
{
MemoryStream ms = new MemoryStream();
//pic.Image.Save(ms, ImageFormat.Png);
//Stream impStream;
pic.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
imgdata = ms.ToArray();
if (picpath != "" || imgdata != null)
{
scm.Parameters.Add(_db.GetParameter("@MPicture", imgdata));
}
}
海阔天高
posted @
2009-10-27 14:59
丁晨
阅读(
262)
评论()
编辑
收藏
举报