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

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

问题描述

我使用的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);



我想这个图像存储在数据表中。我如何能做到这一点。

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

推荐答案

您可以像下面这样做 -

You can do it like this -

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

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天全站免登陆