获取DatagridView列的图片,该如何处理
获取DatagridView列的图片
DatagridView一列中存储了图片信息,怎么取出来?
------解决方案--------------------
Cells["picture"]就是存储图片的那一列。获取方法如下:
object pic_value = this.dgView.SelectedRows[0].Cells["picture"].Value;
Form f = new Form();
f.BackgroundImage = GetImageByBytes((byte[])pic_value);
f.Show();
public static Image GetImageByBytes(byte[] bytes)
{
try
{
if (bytes.Length == 0) return null;
Image photo = null;
using (MemoryStream ms = new MemoryStream(bytes))
{
ms.Write(bytes, 0, bytes.Length);
photo = Image.FromStream(ms, true);
}
return photo;
}
catch
{
return null;
}
}
DatagridView一列中存储了图片信息,怎么取出来?
------解决方案--------------------
Cells["picture"]就是存储图片的那一列。获取方法如下:
object pic_value = this.dgView.SelectedRows[0].Cells["picture"].Value;
Form f = new Form();
f.BackgroundImage = GetImageByBytes((byte[])pic_value);
f.Show();
public static Image GetImageByBytes(byte[] bytes)
{
try
{
if (bytes.Length == 0) return null;
Image photo = null;
using (MemoryStream ms = new MemoryStream(bytes))
{
ms.Write(bytes, 0, bytes.Length);
photo = Image.FromStream(ms, true);
}
return photo;
}
catch
{
return null;
}
}