从流中投射图像
本文关键字:图像 | 更新日期: 2023-09-27 18:14:36
我使用单元格点击事件的数据网格视图,我发现问题试图从流投射图像
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;
}
这一行没有意义:
(Image.FromStream(stream)abaanaCCDataGridView.SelectedRows[0].Cells[this.dataGridViewImageColumn1.Name].Value
我不明白你为什么把Image.FromStream(stream)
和abaanaCCDataGridView...
放在一起?
基本上你做的是正确的。从您的byte[]
中获取MemoryStream
并呼叫Image.FromStream()
。
所以我认为这些行对你有用…
byte[] mydata = (byte[])this.abaanaDataSet.abaanaCC.Rows[0]["CCImage"];
MemoryStream stream = new MemoryStream(mydata);
this.PpicBox.Image = Image.FromStream(stream);
…byte[]
的内容是否有效