本文介绍了如何连接mutli ip camera和array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当我尝试使用阵列连接两个IP摄像机(dlink-930l)时,我遇到了问题。我使用AForge库。所有视频仅交替显示在一个图片框中。我该怎么做才能在不同的图片框中连接每个摄像头。我可以创建数组eventframehandler吗? 使用 AForge.Video; public MJPEGStream [] VideoStream = new MJPEGStream [ 2 ]; private string [] MetaUrl = { http://192.168.0.3/video.cgi?, http://192.168.0.2/video.cgi}?; private void Form1_Load( object sender,EventArgs e) { for ( int i = 0 ; i < VideoStream.Length; i ++) { VideoStream [i] = new MJPEGStream(); VideoStream [i] .Source = MetaUrl [i]; VideoStream [i] .Login = admin; VideoStream [i] .Password = ; } } 私有 void button1_Click( object sender,EventArgs e) { for ( int i = 0 ; i < VideoStream.Length; i ++) { VideoStream [i] .Start(); VideoStream [i] .NewFrame + = new NewFrameEventHandler(VideoStream_NewFrame1); k = i; } } public int k = 0 ; private void VideoStream_NewFrame1( object sender,NewFrameEventArgs eventArgs) { Bitmap FrameData = new Bitmap(eventArgs.Frame); PictureBox [] box = new PictureBox [ 2 ]; 框[ 0 ] = pictureBox1; 框[ 1 ] = pictureBox2; box [k] .Image = FrameData; } 谢谢大师.... 解决方案 不确定这会解决您的问题,但是当您为NewFrame事件创建事件处理程序时 VideoStream [i] .NewFrame + = new NewFrameEventHandler(VideoStream_NewFrame1); 你最终会对两个摄像头使用相同的方法。 这意味着您需要使用sender参数来确定哪个摄像头正在调用该方法。 [更新] 使用 AForge.Video; public MJPEGStream [] VideoStream = new MJPEGStream [ 2 ]; private string [] MetaUrl = { http://192.168.0.3/video.cgi?, http://192.168.0.2/video.cgi}?; 私人 PictureBox []框; 私人 void Form1_Load( object sender,EventArgs e) { box = new PictureBox [VideoStream.Length]; for ( int i = 0 ; i < VideoStream.Length ; i ++) { VideoStream [i] = new MJPEGStream(); VideoStream [i] .Source = MetaUrl [i]; VideoStream [i] .Login = admin; VideoStream [i] .Password = ; boxes [i] .Tag = VideoStream [i]; } } [已更新] private void button1_Click( object sender,EventArgs e) { for ( int i = 0 ; i < VideoStream.Length; i ++) { VideoStream [i] .Start(); VideoStream [i] .NewFrame + = new NewFrameEventHandler(VideoStream_NewFrame1); } } 私有 void VideoStream_NewFrame1( object sender,NewFrameEventArgs eventArgs) { [Updated] MJPEGStream vs =(sender as MJPEGStream); // 我认为MJPEGStream将是 if (vs!= null ) { Bitmap FrameData = new 位图(eventArgs.Frame); foreach (PictureBox框在框中) { if ((MJPEGStream)box.Tag == vs) // 您可能需要修改此比较。 { box.Image = FrameData; break ; } } } } 如果MJPEGStream类包含标签属性,它会更容易使用。 我尝试编辑你的解决方案,它的工作!!!!!!!!!!!!!!!!!!!! !!!!! ..谢谢大师George Jonsson,这里是我编码的代码...... 。 。 .. // 私人PictureBox []框; public PictureBox [] boxes = new PictureBox [ 2 ]; private void Form1_Load( object sender,EventArgs e) { // boxes = new PictureBox [VideoStream.Length] ; //它的制作框始终为空 框[ 0 ] = pictureBox1; 框[ 1 ] = pictureBox2; ... ... } private void VideoStream_NewFrame1( object sender,NewFrameEventArgs eventArgs) { ... ... // 休息;它只能查看一个ip摄像头...... } i have a problem when i try connect two IP camera (dlink-930l) using array. i use AForge library. all of video only shows in one picturebox alternately. what should i do to connect each camera in different picturebox. can i create array eventframehandler ?using AForge.Video;public MJPEGStream[] VideoStream = new MJPEGStream[2]; private string[] MetaUrl = {"http://192.168.0.3/video.cgi?","http://192.168.0.2/video.cgi?"};private void Form1_Load(object sender, EventArgs e) { for (int i = 0; i < VideoStream.Length; i++) { VideoStream[i] = new MJPEGStream(); VideoStream[i].Source = MetaUrl[i]; VideoStream[i].Login = "admin"; VideoStream[i].Password = ""; } } private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < VideoStream.Length; i++) { VideoStream[i].Start(); VideoStream[i].NewFrame += new NewFrameEventHandler(VideoStream_NewFrame1); k = i; } } public int k=0; private void VideoStream_NewFrame1(object sender, NewFrameEventArgs eventArgs) { Bitmap FrameData = new Bitmap(eventArgs.Frame); PictureBox[] box = new PictureBox[2]; box[0] = pictureBox1; box[1] = pictureBox2; box[k].Image = FrameData; }thank you master.... 解决方案 Not sure this will solve your problem, but when you create the event handler for the NewFrame eventVideoStream[i].NewFrame += new NewFrameEventHandler(VideoStream_NewFrame1);you will end up using the same method for both cameras.This means that you need to make use of the sender parameter to figure out which camera is calling the method.[Updated]using AForge.Video;public MJPEGStream[] VideoStream = new MJPEGStream[2]; private string[] MetaUrl = {"http://192.168.0.3/video.cgi?","http://192.168.0.2/video.cgi?"};private PictureBox[] boxes;private void Form1_Load(object sender, EventArgs e){ boxes = new PictureBox[VideoStream.Length]; for (int i = 0; i < VideoStream.Length; i++) { VideoStream[i] = new MJPEGStream(); VideoStream[i].Source = MetaUrl[i]; VideoStream[i].Login = "admin"; VideoStream[i].Password = ""; boxes[i].Tag = VideoStream[i]; }}[Updated]private void button1_Click(object sender, EventArgs e){ for (int i = 0; i < VideoStream.Length; i++) { VideoStream[i].Start(); VideoStream[i].NewFrame += new NewFrameEventHandler(VideoStream_NewFrame1); }}private void VideoStream_NewFrame1(object sender, NewFrameEventArgs eventArgs){ [Updated] MJPEGStream vs = (sender as MJPEGStream); // I think MJPEGStream will be the type if (vs != null) { Bitmap FrameData = new Bitmap(eventArgs.Frame); foreach (PictureBox box in boxes) { if ((MJPEGStream)box.Tag == vs) // You might have to modify this comparison. { box.Image = FrameData; break; } } } }If the class MJPEGStream contains a Tag property, it would be easier to use that.i try edit your solution, and it's work !!!!!!!!!!!!!!!!!!!!!!!!!.. thank you master George Jonsson, here the code i have edited from your code... ....// private PictureBox[] boxes;public PictureBox[] boxes = new PictureBox[2];private void Form1_Load(object sender, EventArgs e) { // boxes = new PictureBox[VideoStream.Length]; //it's make boxes is always null boxes[0] = pictureBox1; boxes[1] = pictureBox2; ... ... }private void VideoStream_NewFrame1(object sender, NewFrameEventArgs eventArgs) { ... ... //breaks; it makes only one ip camera is viewed... } 这篇关于如何连接mutli ip camera和array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-27 04:42