socket传输图片接收时,出现GDI+ 中发生一般性错误
anya 2008-11-26 12:29:32 如题.(Winform程序)接收图片的代码如下:
private void button1_Click(object sender, EventArgs e)
{
//设置接收数据缓冲区的大小
byte[] b = new byte[2000001];
System.Net.Sockets.Socket hostsocket = receivesocket.Accept();
//如何确定该数组大小
System.IO.MemoryStream fs = new System.IO.MemoryStream();
//接收数据
hostsocket.Receive(b);
fs.Write(b, 0, b.Length);
Bitmap Img = new Bitmap(fs);
pictureBox1.Image = Img;
//关闭写文件流
fs.Close();
//关闭接收数据的Socket
hostsocket.Shutdown(System.Net.Sockets.SocketShutdown.Receive);
hostsocket.Close();
}
总是在执行到" Bitmap Img = new Bitmap(fs);"这句的时候,出现错误提示--------GDI+ 中发生一般性错误.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
谢谢.