开发者

C# Video Streaming

I'm trying to do a application with video stream, and by now I can send only one image from the server to the client. When I try to send more than only one image at 开发者_StackOverflow中文版the client I receive the following error: "Parameter is not valid." at pictureBox1.Image = new Bitmap(ms);

Client side code:

while((data = cliente.receiveImage()) != null)
{

   ms = new MemoryStream(data);
   pictureBox1.Image = new Bitmap(ms);
   ms.Close();

}

Server side code (this code is repeated continuously):

servidor.sendImage(ms.GetBuffer());


ms.GetBuffer() returns the entire buffer of the memory stream, including any extra unused portion.
You should call ToArray(), which only returns actual contents.

(Or, your data might be invalid for some other reason, such as an issue in sendImage or receiveImage)


Images are nit-picky things, and you have to have the entire set of bytes that comprise the image in order to reconstruct an image.

I would bet my left shoe that the issue is that when the client object is receiving data, it's getting it in chunks comprised of partial images, not the whole image at once. This would cause the line that says

pictureBox1.Image = new Bitmap(ms);

to fail because it simply doesn't have a whole image's bytes.

Alternatives

  • Rather than having the server push images out to the client, perhaps another approach would be to have the client pull images from the server.

  • Use an existing streaming mechanism. I personally think that streaming video manually from C# may be more complex than you're bargaining for, and I'd humbly recommend using an existing component or application to stream the video rather than writing your own. There are already so many different options out there (wmv, Flash, and a hundred more) that you're reinventing a wheel that really doesn't need to be re-invented.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜