本文介绍了如何从datagridview加载图片框中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到错误无法从System.String转换为System.Byte []代码如下:
I am getting error "Cannot convert from System.String to System.Byte[]" on below code:
private void dgvProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
byte[] imgbyte = (byte[])dgvProduct.CurrentRow.Cells[11].Value;
GetPhoto(imgbyte);
}
我的尝试:
What I have tried:
private void dgvProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
byte[] imgbyte = (byte[])dgvProduct.CurrentRow.Cells[11].Value;
GetPhoto(imgbyte);
}
private void GetPhoto(byte[] imgbyte)
{
Image newImage;
using (MemoryStream ms = new MemoryStream(imgbyte, 0, imgbyte.Length))
{
ms.Write(imgbyte, 0, imgbyte.Length);
newImage = Image.FromStream(ms, true);
pbItem.Image = newImage;
}
}
推荐答案
byte[] imgbyte = (byte[])dgvProduct.CurrentRow.Cells[11].Value;
并检查单元格中的内容。
我们不能为您做到这一点 - 我们没有访问您的数据......
And examine what is in the cell.
We can't do that for you - we don't have any access to your data...
这篇关于如何从datagridview加载图片框中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!