我用C#呼叫Aforge庫實作攝像頭錄像時,出現除第一幀以外,其余像素點低的情況(畫面不清晰),望大神指點下。
以下時原始碼:
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.DirectShow;
using AForge.Video.FFMPEG;
using AForge.Video;
using AForge.Controls;
using AForge.Imaging;
using AForge.Imaging.Filters;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private int count=0;
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource;
private VideoFileWriter vfw;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
videoSourcePlayer1.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
count = 1;
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
{
MessageBox.Show("未發現視頻設備!");
return;
}
videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
videoSource.VideoResolution = videoSource.VideoCapabilities[0];
videoSourcePlayer1.VideoSource = videoSource;
}
private void button2_Click(object sender, EventArgs e)
{
videoSourcePlayer1.Stop();
}
private void button3_Click(object sender, EventArgs e)
{
if (videoSource.IsRunning && videoSourcePlayer1.IsRunning)
{
if (vfw != null)
{
vfw.Close();
vfw.Dispose();
}
vfw = new VideoFileWriter();
videoSource.NewFrame += new NewFrameEventHandler((object senders, NewFrameEventArgs es) =>
{
count += 1;
//寫入到視頻
vfw.WriteVideoFrame(es.Frame);
});
vfw.Open("D://test.avi", videoSource.VideoResolution.FrameSize.Width, videoSource.VideoResolution.FrameSize.Height, videoSource.VideoResolution.FrameRate, VideoCodec.Default);
}
}
private void button4_Click(object sender, EventArgs e)
{
vfw.Close();
videoSourcePlayer1.SignalToStop();
videoSourcePlayer1.WaitForStop();
videoSource.Stop();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/208895.html
標籤:C#
上一篇:C# 如何使用反射讀取資料庫
下一篇:c#一個好奇的問題
