写:
FileStream fs = new FileStream("图片路径", FileMode.Open);
Byte[] imagebytes = new byte[fs.Length]; //二进制转换
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length)); //读取二进制流
读:
//dr["content_"]为数据库保存的二进制图片数据
MemoryStream ms = new MemoryStream((byte[])dr["content_"]);//把照片读到MemoryStream里
Image imageBlob = Image.FromStream(ms, true);//用流创建Image
pictureBox1.Image = imageBlob;//输出图片
本文介绍了一种方法,通过使用C#的FileStream、BinaryReader和MemoryStream来从数据库中读取二进制图片数据,并将其显示在PictureBox上。详细步骤包括创建FileStream对象、读取二进制流、将数据转换为MemoryStream,然后使用Image.FromStream方法创建Image对象,最后将Image对象显示在PictureBox中。
927

被折叠的 条评论
为什么被折叠?



