将ms访问的二进制文件转换为Imagelist的Image
本文关键字:Imagelist Image 转换 二进制文件 ms 访问 | 更新日期: 2023-09-27 18:29:07
我刚刚将位图缩略图转换为二进制代码,存储到我的MS Access数据库中。我现在正试图将二进制数据转换回图像格式,以存储到我的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);
}
}
如果有人能帮助我那就太好了。谢谢
您需要将其强制转换为字节数组:
Image.FromStream(new MemoryStream((byte[]) reader["Images"]))