首页 新闻 搜索 专区 学院

当做的一个项目要显示图片,图片要从数据库中读取

0
[待解决问题]

这该怎么办

杀  手的主页 杀 手 | 菜鸟二级 | 园豆:213
提问于:2011-06-14 09:05
< >
分享
所有回答(4)
0
存放的二进制数据如下:
string fullpath = openFileDialog1.FileName;
FileStream fs
= new FileStream(fullpath, FileMode.Open);
byte[] imagebytes = new byte[fs.Length];
BinaryReader br
= new BinaryReader(fs);
imagebytes
= br.ReadBytes(Convert.ToInt32(fs.Length));

读取如下:
byte[] imagebytes = null;
//从数据库中读取出数据赋值给imagebytes ----
MemoryStream ms = new MemoryStream(imagebytes);
Bitmap bmpt
= new Bitmap(ms);
pictureBox1.Image
= bmpt;
dwwwing | 园豆:661 (小虾三级) | 2011-06-14 09:55
0

Response.ContentType = "image/jpeg";
.......
将图片写入Response.OutputStream
Response.End();

Jeremy Liu | 园豆:705 (小虾三级) | 2011-06-14 10:29
0

你可以在数据库设置图片路径,只要读取路径就可以了,不过那个路径下必须有那个图片

蓦然回首的思念 | 园豆:900 (小虾三级) | 2011-06-14 13:49
0

可以将图片进行Base64转码,存入数据库

View Code
1 MemoryStream stream = new MemoryStream();
2 Image img = new Bitmap(@"C:\\picture.jpg");
3 img.Save(stream, ImageFormat.Jpeg);
4 string image = Convert.ToBase64String(stream.ToArray());
5 this.txtBinary.Text = image;


取出来时候再转成图片

View Code
1 string strImage = this.txtToPicture.Text;
2 byte[] image = Convert.FromBase64String(strImage);
3 MemoryStream stream = new MemoryStream(image);
4 Image img = Image.FromStream(stream);
5 this.picToPicture.Image = img;
王元勋 | 园豆:413 (菜鸟二级) | 2011-06-15 11:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册