例如网上有这个相机:
http://cam-i.switch.ch/login.cgi?t=j&l=1&ch=2
它使用java。我想每隔 X 秒从相机中获取图像并将其显示在图片框上。
这是我试图使用的代码:
string sourceURL = "http://cam-i.switch.ch/login.cgi?t=j&l=1&ch=2";
byte[] buffer = new byte[100000];
int read, total = 0;
// create HTTP request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
req.Credentials = new NetworkCredential("username", "pass");
// 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(
new MemoryStream(buffer, 0, total));
pictureBox1.Image = bmp;
我在这一行得到 ArgumentException:
Bitmap bmp = (Bitmap)Bitmap.FromStream(
new MemoryStream(buffer, 0, total));
我看到缓冲区包含许多数字并且总数包含 15149 参数无效
System.ArgumentException was unhandled
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at SearchLiveCameras.Form1..ctor() in d:\C-Sharp\SearchliveCameras\SearchLiveCameras\SearchLiveCameras\Form1.cs:line 43
at SearchLiveCameras.Program.Main() in d:\C-Sharp\SearchliveCameras\SearchLiveCameras\SearchLiveCameras\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
我想让我输入的每个在线相机链接都能在pictureBox1上获得实时信息