how to fix ArgumentOutOfRangeException in a string

while((read = stream.Read(buffer, total, 1000)) != 0) 

Full text of the method:

 private void getFrame() { string sourceURL = "https://geocam.tv/streamer/2222.mjpg"; byte[] buffer = new byte[1280 * 800]; int read, total = 0; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL); WebResponse resp = req.GetResponse(); Stream stream = resp.GetResponseStream(); while((read = stream.Read(buffer, total, 1000)) != 0) { total += read; } Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, total)); pictureBox1.Image = bmp; } 

I want to broadcast videos from https://geocam.tv/streamer/2222.mjpg

  • And the size of the buffer is exactly enough? - pavel
  • @pavel how to determine what is enough - NoProgress
  • Well, for example, use dynamic arrays ArrayList for example and does not care about it. And it is worth fully lead the message line, it says to what index was the appeal. - pavel
  • @NoProgress, you can try Length check - Grundy
  • @pavel I do not understand this topic, show an example - NoProgress

1 answer 1

used the MJPEG Decoder

 public partial class Form3 : Form { MjpegDecoder _mjpeg; public Form3() { InitializeComponent(); _mjpeg = new MjpegDecoder(); _mjpeg.FrameReady += mjpeg_FrameReady; } private void button1_Click(object sender, EventArgs e) { _mjpeg.ParseStream(new Uri("https://geocam.tv/streamer/2222.mjpg")); } private void mjpeg_FrameReady(object sender, FrameReadyEventArgs e) { pictureBox1.Image = e.Bitmap; } 

and everything works