将图像存储在DataTable中

时间:2009-10-09 11:04:16

标签: wpf image datatable icons default

我想将图像存储到我的数据表中,并且在添加列时我想设置其默认值,向您发送带有复选框的代码..

public void addCheckBoxesRuntime(){ for(int i = 0; i< InformationOne.Length; i ++)             {                 dt = new DataColumn(InformationOne [i] [1] +“(”+ InformationOne [i] [0] +“)”);

            dt.DataType = typeof(Boolean);

            viewDataTable.Columns.Add(dt);
            dt.DefaultValue = false;                
        }

}

1 个答案:

答案 0 :(得分:2)

创建一个DataColumn类型string,然后将图像的字符串二进制文件存储到字段中。或者,使用二进制本身和byte[]

应该100%工作。

有些事情如下:

public string ImageConversion(System.Drawing.Image image)
{
    if (image == null) 
       return string.Empty;

    using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
    {
       image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Gif);

       string value = string.Empty;

       for (int intCnt = 0; intCnt <= memoryStream.ToArray.Length - 1; intCnt++) 
       {
           value = value + memoryStream.ToArray(intCnt) + ",";
       }

       return value;
    }
}