我正在使用单元格点击事件进行数据网格视图,并且发现尝试从流中投射图像时遇到问题
private void abaanaCCDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
this.Ptxtspn_code.Text = this.abaanaCCDataGridView.SelectedRows[0].Cells[this.dataGridViewTextBoxColumn2.Name].Value.ToString();
//this.PtxtFname.Text
this.abaanaCCTableAdapter.Fill(this.abaanaDataSet.abaanaCC);
byte[] mydata = (byte[])this.abaanaDataSet.abaanaCC.Rows[0]["CCImage"];
//byte[] mydata = (byte[])this.abaanaCCDataGridView.SelectedRows[0].Cells[this.dataGridViewImageColumn1.Name];
MemoryStream stream = new MemoryStream(mydata);
//Image img = Image.FromStream(stream);
this.PpicBox.Image = (Image.FromStream(stream))abaanaCCDataGridView.SelectedRows[0].Cells[this.dataGridViewImageColumn1.Name].Value;
}
答案 0 :(得分:2)
这条线毫无意义:
(Image.FromStream(stream)abaanaCCDataGridView.SelectedRows[0].Cells[this.dataGridViewImageColumn1.Name].Value
我看不出为什么要将Image.FromStream(stream)
和abaanaCCDataGridView...
放在一起?
基本上你所做的并不是错误的。从MemoryStream
获取byte[]
并致电Image.FromStream()
。
所以我认为这些线条对你有用......
byte[] mydata = (byte[])this.abaanaDataSet.abaanaCC.Rows[0]["CCImage"];
MemoryStream stream = new MemoryStream(mydata);
this.PpicBox.Image = Image.FromStream(stream);
...如果byte[]
的内容有效。