我尝试通过TCP套接字将摄像头服务器流式传输到客户端,但我从客户端获得错误
' System.ArgumentException'发生在System.Drawing.dll - 参数中 无效。
在第Bitmap bitmap = new Bitmap(ms);
行
这是服务器代码
byte[] buffer = new byte[100000];
var converter = new System.Drawing.ImageConverter();
while (true) // find a better way to determine that the picture is still updating?
{
if (clientSocket.Connected)
{
bmp = new Bitmap(bit);
Console.Write(bmp);
buffer = (byte[])converter.ConvertTo(bmp, typeof(byte[]));
clientSocket.Send(buffer, buffer.Length, SocketFlags.None);
Console.Write(i++);
GC.Collect();
}
else { MessageBox.Show("disconnect"); }
}
这是客户端
bool success = true;
while (success)
{
if (s.Connected)
{
byte[] buffer = new byte[100000];
s.Receive(buffer, buffer.Length, SocketFlags.None);
MemoryStream ms = new MemoryStream(buffer);
ms.Write(buffer, 0, buffer.Length);
Bitmap bitmap = new Bitmap(ms);
pictureBox1.Image = bitmap;
//ms.SetLength(0);
GC.Collect();
}
else
{
MessageBox.Show("Disconnect");
}
}
success = true;
return;