我在C#窗体中创建了一个程序我的窗体中有很多函数,其中包括两个连接到dabase的datagrid视图,包括一个直接连接到我的PC的摄像机我使用AForge DLL参考连接到我刚刚找到的摄像机设备教程youtube,它对我来说是完美的,正如我前面说过的,我在一个表单中包含了太多的程序,包括那个相机,并且它出去了,相机需要调整到一个小的分辨率,所以我决定做一个弹出当我点击表单上的按钮时,该按钮必须显示更宽的分辨率。如何在点击按钮时使用图片框弹出相机?
这是我的相机的代码。
//Camera
// get the devices name
private void getCamList()
{
try
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
comboBox1.Items.Clear();
if (videoDevices.Count == 0)
throw new ApplicationException();
DeviceExist = true;
foreach (FilterInfo device in videoDevices)
{
comboBox1.Items.Add(device.Name);
}
comboBox1.SelectedIndex = 0; //make dafault to first cam
}
catch (ApplicationException)
{
DeviceExist = false;
comboBox1.Items.Add("No capture device on your system");
}
}
//refresh button
private void refresh_Click(object sender, EventArgs e)
{
getCamList();
}
//toggle start and stop button
private void start_Click(object sender, EventArgs e)
{
if (start.Text == "&Start")
{
if (DeviceExist)
{
videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
CloseVideoSource();
videoSource.DesiredFrameSize = new Size(160, 120);
//videoSource.DesiredFrameRate = 10;
videoSource.Start();
lblCam.Text = "Device running...";
start.Text = "&Stop";
}
else
{
lblCam.Text = "Error: No Device selected.";
}
}
else
{
if (videoSource.IsRunning)
{
CloseVideoSource();
lblCam.Text = "Device stopped.";
start.Text = "&Start";
}
}
}
//eventhandler if new frame is ready
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap img = (Bitmap)eventArgs.Frame.Clone();
//do processing here
pictureBox1.Image = img;
}
//close the device safely
private void CloseVideoSource()
{
if (!(videoSource == null))
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource = null;
}
}
//prevent sudden close while device is running
private void Form1_FormClosed(object sender, FormClosingEventArgs e)
{
CloseVideoSource();
}
} }
我也贴一张照片,让您进一步了解我在说什么。 正如你可以看到在右下角我有一个弹出按钮在那里老实告诉你我已经尝试过不同的方法,但没有工作不幸的是我不能发布我试过,因为我昨天创建它,并不能再撤消我试过的代码。任何想法?
实际上是否存在一个缺少标点符号的混乱问题? – 2013-04-30 13:07:16