基本步骤:
读取:
1.使用byte[]存放数据库中对应的image类型子段的值
2.用byte[]构造一个MemoryStream
3.使用GDI+中public Bitmap(Stream stream)构造图片
4.pictureBox.Image=刚才创建的bitmap
保存:
1.用stream读取一个图像文件
2.再利用stream的Read方法构造一个byte[]
3.把byte[]存入image
示例:
读取:
1.使用byte[]存放数据库中对应的image类型子段的值
2.用byte[]构造一个MemoryStream
3.使用GDI+中public Bitmap(Stream stream)构造图片
4.pictureBox.Image=刚才创建的bitmap
保存:
1.用stream读取一个图像文件
2.再利用stream的Read方法构造一个byte[]
3.把byte[]存入image
示例:
1//读出图片
2byte[] bytes = (byte[])ds.Tables[0].Rows[0][1];
3MemoryStream memStream = new MemoryStream(bytes);
4Bitmap myImage = new Bitmap(memStream);
5pictureBox.Image = myImage;
2byte[] bytes = (byte[])ds.Tables[0].Rows[0][1];
3MemoryStream memStream = new MemoryStream(bytes);
4Bitmap myImage = new Bitmap(memStream);
5pictureBox.Image = myImage;
1//存入图片
2Steam myStream = openFileDialog.OpenFile();
3int length = (int)myStream.Length;
4byte[] bytes = new byte[length];
5myStream.Read(bytes,0,length);
6myStream.Close();
7ds.Tables[0].Rows[0][1] = bytes;
2Steam myStream = openFileDialog.OpenFile();
3int length = (int)myStream.Length;
4byte[] bytes = new byte[length];
5myStream.Read(bytes,0,length);
6myStream.Close();
7ds.Tables[0].Rows[0][1] = bytes;