将二进制从ms访问转换为Image for Imagelist

时间:2012-03-26 17:46:39

标签: c# image ms-access bitmap binary

我刚刚将位图缩略图转换为二进制代码以存储到我的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);

        }



    }

如果有人能帮助我那会很棒。谢谢!

1 个答案:

答案 0 :(得分:1)

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

Image.FromStream(new MemoryStream((byte[]) reader["Images"]))