繁体   English   中英

在C#中从数据库检索图像

[英]Retrieve image from database in c#

我的数据库中有一个表,其中包含一个Image_ID,Image,Image_Name和Recipe_ID。

我正在尝试以单独的形式进行编辑。 因此,当在dataGridView中选择一行时,它将在编辑表单中打开,并且相关区域填充有数据。

我可以使用Image以外的所有数据来执行此操作。 显然,我需要以某种方式进行转换,就像我对文本字段所做的那样,但是我不知道如何进行转换。

编辑图像行

//Edit image row
        private void EditImageBtn_Click(object sender, EventArgs e)
        {
            try
            {
                EditImageForm Image = new EditImageForm();

                Image.imageidTxt.Text = this.imageGridView.CurrentRow.Cells[0].Value.ToString();
                //Image.picImg.Text = this.imageGridView.CurrentRow.Cells[1].Value.ToString();
                Image.nameTxt.Text = this.imageGridView.CurrentRow.Cells[2].Value.ToString();
                Image.recipeCombo.Text = this.imageGridView.CurrentRow.Cells[3].Value.ToString();

                Image.ShowDialog();
                loadImageTable();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }

如果图像存储的是字节,则可以尝试以下类似的方法将位图转换为图像类型:

byte[] bitmap = this.imageGridView.CurrentRow.Cells[1].Value;    
Image image = Image.FromStream(new MemoryStream(bitmap))

更多信息: https : //msdn.microsoft.com/zh-cn/library/9t4syfhh.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM