赞
踩
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "*jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP";
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- this.pictureBox1.Image = new Bitmap(ofd.FileName);
- }
如果将图片存到数据库,一种可以存储图片的路径,但路径可能变化,不推荐,更多的是直接存储图片的字节数组
using System.IO;
- MemoryStream ms = new MemoryStream();
- this.pictureBox1.Image.Save(ms, this.pictureBox1.Image.RawFormat);
- byte[] imgBytes = ms.ToArray();
- byte[] images = (byte[])dr["img"]; //从数据库中读出图片所在栏位
- MemoryStream ms = new MemoryStream(images);
- pictureBox1.Image = Image.FromStream(ms);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。