数据表中的图像 [英] Image in datatable

查看:74
本文介绍了数据表中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OpenFileDialog读取图像。示例代码如下:

I read image by using OpenFileDialog. Sample code is below:

openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != null)
   if (picBoardImage.Image != null)
{
    picBoardImage.Image.Dispose();
}
picBoardImage.Image = Image.FromFile(openFileDialog1.FileName);

我想将此图像存储在datatable中。我该怎么做?

I want to store this image in datatable. How can I do that?

推荐答案

你可以这样做 -

DataTable table = new DataTable("ImageTable"); //Create a new DataTable instance.

DataColumn column = new DataColumn("MyImage"); //Create the column.
column.DataType = System.Type.GetType("System.Byte[]"); //Type byte[] to store image bytes.
column.AllowDBNull = true;
column.Caption = "My Image";

table.Columns.Add(column); //Add the column to the table.

然后,在此表中添加一个新行,并设置 MyImage 列。

Then, add a new row to this table and set the value of the MyImage column.

DataRow row = table.NewRow();
row["MyImage"] = <Image byte array>;
tables.Rows.Add(row);

编辑:您可以查看 CodeProject文章,用于将图像转换为字节数组的帮助。

You can take a look at this CodeProject article for help on converting an image to a byte array.

这篇关于数据表中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆