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!它工作完美 –