2012-03-26 30 views
0

我刚刚将位图缩略图转换为二进制代码以存储到我的MS Access数据库中。我现在试图将该二进制数据转换回图像格式存储到我的Imagelist中。我现在的代码是。将二进制从ms访问转换为Imagelist的图像

private void Form1_Load(object sender, EventArgs e) 
    { 
     vcon.Open(); 
     string get = "Select Path, Images FROM IMGSTR"; 
     OleDbCommand cmdget = new OleDbCommand(get, vcon); 
     OleDbDataReader reader; 
     reader = cmdget.ExecuteReader(); 

     while (reader.Read()) 
     { 
      string path = reader["Path"].ToString(); 

      // should I convert binary into a string? 
      string thumbnail = reader["Images"].ToString(); 

      // How to convert the binary data from the 
      // MS database back to a bitmap image. 

      //I need to convert the binary back to bitmap to work 
      //in this imagelist. 
      this.imageList1.Images.Add(thumbnail); 

     } 



    } 

如果有人可以帮助我,将是巨大的。谢谢!

回答

1

您需要将其转换为字节数组:

Image.FromStream(new MemoryStream((byte[]) reader["Images"])) 
相关问题