数据库读取二进制图片显示到PictureBox中

1、已知路径,加载本地图片到Image中

  Image img = Image.FromFile("路径"); 

2、数据库中读取二进制图片

  string strSql = "Select Top 1 ImageContent From TT_ImageFileSave)";

  Byte[] byteImage = new Byte[0];

  byteImage = (Byte[])(DbHelperSQL.GetSingle(strSql));

  MemoryStream stmBLOBData = new MemoryStream(byteImage);

  picCarInfo.Image = Image.FromStream(stmBLOBData);

3、将已知路径图片转换为二进制

  string strImagePath = AppDomain.CurrentDomain.BaseDirectory + "//Tickets//Ticket.jpg";

  FileStream fileStream = new FileStream(strImagePath, FileMode.Open, FileAccess.Read);

  BinaryReader binaryReader = new BinaryReader(fileStream);

  byte[] byteImage = binaryReader.ReadBytes((int)fileStream.Length);

  binaryReader.Close(); fileStream.Close(); File.Delete(strImagePath);

  return byteImage;

4、将现有Image图片转化为二进制 

    MemoryStream mStream = new MemoryStream();
  byte[] bytImagedata = null; 
  pictureBox1.Image.Save(Ms,System.Drawing.Imaging.ImageFormat.Bmp);  

  bytImagedata = mStream.GetBuffer();     return bytImagedata;

 

http://www.cnblogs.com/zhangpengshou/archive/2011/04/24/1749391.html

数据库读取二进制图片显示到PictureBox中,布布扣,bubuko.com

数据库读取二进制图片显示到PictureBox中

上一篇:Oracle Ebs R12 SLA与GL关系变化


下一篇:ubuntu下搭建nginx+mysql+php-fpm站点