I am designing an UI using windows forms app and i need to transfer the real-time frame of webcam capture between the forms.
![128334-form2.png][1]
This is my form2 and the webcam will capture the frame here and its code is shown below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;
namespace MUI
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
FilterInfoCollection filterInfoCollection;
VideoCaptureDevice videoCaptureDevice;
public void videoCaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
}
public Image img;
private void button1_Click(object sender, EventArgs e)
{
try
{
var cam = filterInfoCollection[comboBox1.SelectedIndex].MonikerString;
videoCaptureDevice = new VideoCaptureDevice(cam);
videoCaptureDevice.NewFrame += videoCaptureDevice_NewFrame;
videoCaptureDevice.Start();
img = pictureBox1.Image;
Form7 f7 = new Form7();
f7.Show();
}
catch (Exception)
{
throw;
}
}
private void button3_Click(object sender, EventArgs e)
{
videoCaptureDevice.Stop();
pictureBox1.Image = null;
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
videoCaptureDevice.Stop();
pictureBox1.Image = null;
}
public void Form2_Load(object sender, EventArgs e)
{
try
{
#region Devices
filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo filterInfo in filterInfoCollection)
{
comboBox1.Items.Add(filterInfo.Name);
}
comboBox1.SelectedIndex = 0;
videoCaptureDevice = new VideoCaptureDevice();
#endregion
}
catch (Exception)
{
throw;
}
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if (videoCaptureDevice.IsRunning == true)
videoCaptureDevice.Stop();
}
}
}
![128279-form3.png][2]
And here's the form3 that i want to transfer the frame.
I haven't write anything yet in the form2 because I couldn't send the frame.
How can I achieve that?
[1]: /answers/storage/attachments/128334-form2.png
[2]: /answers/storage/attachments/128279-form3.png