我在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