0
我不断收到此错误:指定的参数是有效的值的范围之外 - C#
The specified argument is outside the range of valid values.
当我运行这段代码在C#:
string sourceURL = "http://192.168.1.253/nphMotionJpeg?Resolution=320x240&Quality=Standard";
byte[] buffer = new byte[200000];
int read, total = 0;
// create HTTP request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
req.Credentials = new NetworkCredential("username", "password");
// get response
WebResponse resp = req.GetResponse();
// get response stream
// Make sure the stream gets closed once we're done with it
using (Stream stream = resp.GetResponseStream())
{
// A larger buffer size would be benefitial, but it's not going
// to make a significant difference.
while ((read = stream.Read(buffer, total, 1000)) != 0)
{
total += read;
}
}
// get bitmap
Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0, total));
pictureBox1.Image = bmp;
这条线:
while ((read = stream.Read(buffer, total, 1000)) != 0)
有谁知道什么可能会导致此错误或如何解决它?
在此先感谢
大约只是在做'Bitmap.FromStream(输入)什么'直接? –
Thx!它工作完美 –