private void button2_Click(object sender, System.EventArgs e)
{
IDataObject d = Clipboard.GetDataObject();
if(d.GetDataPresent(DataFormats.Bitmap))
{
Bitmap b = (Bitmap)d.GetData(DataFormats.Bitmap); Byte[] byteBLOBData = new Byte[0];
//byteBLOBData = (Byte[])b; // 这里会出错,无法完成转换
//MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
//pictureBox1.Image= Image.FromStream(stmBLOBData);
pictureBox1.Image= b; //为什么不这样?为什么要用Byte[]?? }
else
{
MessageBox.Show("No bitmap information was contained in the clipboard.");
}
}
{
IDataObject d = Clipboard.GetDataObject();
if(d.GetDataPresent(DataFormats.Bitmap))
{
Bitmap b = (Bitmap)d.GetData(DataFormats.Bitmap); Byte[] byteBLOBData = new Byte[0];
//byteBLOBData = (Byte[])b; // 这里会出错,无法完成转换
//MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
//pictureBox1.Image= Image.FromStream(stmBLOBData);
pictureBox1.Image= b; //为什么不这样?为什么要用Byte[]?? }
else
{
MessageBox.Show("No bitmap information was contained in the clipboard.");
}
}
if (d.GetDataPresent(typeof(System.Drawing.Bitmap))) {
Bitmap b = (Bitmap)d.GetData(typeof(System.Drawing.Bitmap));
this.pictureBox1.Image = b;
}你的程序错误如下:1,byteBLOBData 是长度为0的byte[] 怎么能存东西,付值当然出错?
2,Bitmap 是不能隐或显式的转成Byte[]