我正在尝试通过两个桌面应用程序之间的tcp-ip连接发送图像,但是我遇到了System.ArgumentException:'参数无效。'在System.Drawing.Image bmp行上的接收端出现错误消息= System.Drawing.Image.FromStream(ms);
//sending side
public void sendImage(Bitmap image_to_send)
{
TcpClient client = new TcpClient("127.0.0.1", 1200);
NetworkStream stream = client.GetStream();
MemoryStream ms = new MemoryStream();
image_to_send.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
byte[] bmpBytes = ms.ToArray();
stream.Write(bmpBytes, 0, bmpBytes.Length);
}
//receiving side
TcpClient client = new TcpClient("127.0.0.1", 1200);
NetworkStream stream = client.GetStream();
byte[] buffer = new byte[client.ReceiveBufferSize];
int data = stream.Read(buffer, 0, buffer.Length);
MemoryStream ms = new MemoryStream(buffer);
System.Drawing.Image bmp = System.Drawing.Image.FromStream(ms);
client.Close();