存放的二进制数据如下:
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;
Response.ContentType = "image/jpeg";
.......
将图片写入Response.OutputStream
Response.End();
你可以在数据库设置图片路径,只要读取路径就可以了,不过那个路径下必须有那个图片
可以将图片进行Base64转码,存入数据库
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;
取出来时候再转成图片
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;