日期:2014-05-18 浏览次数:20958 次
byte[] b = (byte[])dt.Rows[0]["Photo"]; //dt为查询出的DataTable,Photo为表里的image字段名称 MemoryStream s = new MemoryStream(b, true); s.Write(b,0,b.Length); Image a = new Bitmap(s); Bitmap bit = new Bitmap(picPhoto.Width, picPhoto.Height); Graphics g = Graphics.FromImage(bit);//从指定的 Image 创建新的 Graphics(绘图)。 g.DrawImage(a, new Rectangle(0, 0, bit.Width, bit.Height), new Rectangle(0, 0, a.Width, a.Height), GraphicsUnit.Pixel); picPhoto.Image = bit;
MemoryStream ms = new MemoryStream();
picPhoto.Image.Save("a.jpg");
FileStream fs = new FileStream("a.jpg", FileMode.Open, FileAccess.Read);
BinaryReader binaryReader = new BinaryReader(fs);
byte[] img = binaryReader.ReadBytes((int)fs.Length);
binaryReader.Close();
fs.Close();
File.Delete("a.jpg");
info.Photo = img; //info为定义的实体类