问题描述
Hello buddy
目前我正在开展与IP Camera(Bosch)相关的项目。我可以使用带有IP地址的网络浏览器访问相机(例如:http://10.64.91.48)。现在我想在窗口窗体上显示视频。在互联网上多次搜索并使用下面的代码,但我面临ArgumentException,仍然无法解决它。我尝试从响应(resp.ContentType)获取内容类型,它显示text / html。
你能帮我解决这个问题吗?任何反馈都将非常感激!
Hello buddy
Currently i am working on a project related to IP Camera (Bosch). I can access the camera using web browser with ip address (ex: http://10.64.91.48). Now i want to display the video on a Window Form. Searching on the internet many times and using below code but i face an ArgumentException, and still can't resolve it. I try to get the content type from response (resp.ContentType), it show me text/html.
Could you please help me to resolve this issue? Any feedback will be very appreciated!
string CameraUrl = this.txt_URL.Text;
if (string.IsNullOrEmpty(CameraUrl) == false)
{
byte [] buffer=new byte[300000];
int read, total = 0;
//Create a HTTP Request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(CameraUrl);
//Request Credential
req.Credentials = new NetworkCredential("user", "user");
//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
MemoryStream memstream = new MemoryStream(buffer, 0, total);
Bitmap img = (Bitmap)Bitmap.FromStream(memstream); // Exception here
this.pictureBox1.Image = img;
}
推荐答案
这篇关于使用C#从IP Camera获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!