我正在使用这个代码片段(见下文)。我不断收到上述错误。谁能告诉我我做错了什么以及如何解决?谢谢。
private static Image<Bgr, Byte> GetImageFromIPCam(string sourceURL)
{
byte[] buffer = new byte[300000];
int read, total = 0;
// create HTTP request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
// get response
WebResponse resp = req.GetResponse();
// get response stream
Stream stream = resp.GetResponseStream();
// read data from stream
while ((read = stream.Read(buffer, total, 1000)) != 0)
{
total += read;
}
// get bitmap
Bitmap bmp = (Bitmap)Bitmap.FromStream( //error occurs here
new MemoryStream(buffer, 0, total)); //error occurs here
Image<Bgr, Byte> img = new Image<Bgr, byte>(bmp);
return img;
}
我想补充一点,这个程序不时运行良好。有些日子它根本不起作用,我不明白为什么。我有一个演示文稿,但我无法承受该程序在那天无法运行。