数据库读取二进制图片显示到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中,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。