我让这段代码接收图像并将其转换为位图图像,但它不起作用。字节数组到位图图像
下面是代码:
public void ReceiveImage()
{
NetworkStream stream = new NetworkStream(socket);
byte[] data = new byte[4];
stream.read(data,0,data.length,0)
int size = BitConverter.ToInt32(data,0);
data = new byte[size];
stream.read(data,0,data.length)
MemoryStream imagestream = new MemoryStream(data);
Bitmap bmp = new Bitmap(imagestream);
picturebox1.Image = bmp;
}
它得到:
Bitmap bmp = new Bitmap(imagestream);
,给我这个错误:
Parameter is not valid
@Tarek ...这是C#代码?当我将它复制到Visual Studio中时,它有一些错别字。 – MikeTWebb 2012-07-30 22:11:56
是它的C#,但是你必须使用System.IO键入 ;使用System.Net.Sockets的 ;使用System.Net的 ; – 2012-07-30 22:14:11
并且还使用System.Drawing.Imaging; – 2012-07-30 22:16:29