首页 新闻 会员 周边 捐助

aforge.net怎么把捕获的视频保存到本机上

0
悬赏园豆:100 [待解决问题]

aforge.net怎么把捕获的视频保存到本机上,或是拍照然后把照片保存到本机

小小小白R的主页 小小小白R | 初学一级 | 园豆:102
提问于:2012-03-04 10:26
< >
分享
所有回答(1)
1

没用过,不过你可以把捕捉视频的代码贴上来看看,然后再给你提供方法。

az235 | 园豆:8483 (大侠五级) | 2012-03-05 15:50
using AForge.Video;
using AForge.Video.DirectShow;

namespace Snapshot_Maker
{
public partial class MainForm : Form
{
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoDevice;
private VideoCapabilities[] videoCapabilities;
private VideoCapabilities[] snapshotCapabilities;

private SnapshotForm snapshotForm = null;

public MainForm( )
{
InitializeComponent( );
}

// Main form is loaded
private void MainForm_Load( object sender, EventArgs e )
{
// enumerate video devices
videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice );

if ( videoDevices.Count != 0 )
{
// add all devices to combo
foreach ( FilterInfo device in videoDevices )
{
devicesCombo.Items.Add( device.Name );
}
}
else
{
devicesCombo.Items.Add( "No DirectShow devices found" );
}

devicesCombo.SelectedIndex = 0;

EnableConnectionControls( true );
}

// Closing the main form
private void MainForm_FormClosing( object sender, FormClosingEventArgs e )
{
Disconnect( );
}

// Enable/disable connection related controls
private void EnableConnectionControls( bool enable )
{
devicesCombo.Enabled = enable;
videoResolutionsCombo.Enabled = enable;
snapshotResolutionsCombo.Enabled = enable;
connectButton.Enabled = enable;
disconnectButton.Enabled = !enable;
triggerButton.Enabled = ( !enable ) && ( snapshotCapabilities.Length != 0 );
}

// New video device is selected
private void devicesCombo_SelectedIndexChanged( object sender, EventArgs e )
{
if ( videoDevices.Count != 0 )
{
videoDevice = new VideoCaptureDevice( videoDevices[devicesCombo.SelectedIndex].MonikerString );
EnumeratedSupportedFrameSizes( videoDevice );
}
}

// Collect supported video and snapshot sizes
private void EnumeratedSupportedFrameSizes( VideoCaptureDevice videoDevice )
{
this.Cursor = Cursors.WaitCursor;

videoResolutionsCombo.Items.Clear( );
snapshotResolutionsCombo.Items.Clear( );

try
{
videoCapabilities = videoDevice.VideoCapabilities;
snapshotCapabilities = videoDevice.SnapshotCapabilities;

foreach ( VideoCapabilities capabilty in videoCapabilities )
{
if ( !videoResolutionsCombo.Items.Contains( capabilty.FrameSize ) )
{
videoResolutionsCombo.Items.Add( capabilty.FrameSize );
}
}

foreach ( VideoCapabilities capabilty in snapshotCapabilities )
{
if ( !snapshotResolutionsCombo.Items.Contains( capabilty.FrameSize ) )
{
snapshotResolutionsCombo.Items.Add( capabilty.FrameSize );
}
}

if ( videoCapabilities.Length == 0 )
{
videoResolutionsCombo.Items.Add( "Not supported" );
}
if ( snapshotCapabilities.Length == 0 )
{
snapshotResolutionsCombo.Items.Add( "Not supported" );
}

videoResolutionsCombo.SelectedIndex = 0;
snapshotResolutionsCombo.SelectedIndex = 0;
}
finally
{
this.Cursor = Cursors.Default;
}
}

// On "Connect" button clicked
private void connectButton_Click( object sender, EventArgs e )
{
if ( videoDevice != null )
{
if ( ( videoCapabilities != null ) && ( videoCapabilities.Length != 0 ) )
{
videoDevice.DesiredFrameSize = (Size) videoResolutionsCombo.SelectedItem;
}

if ( ( snapshotCapabilities != null ) && ( snapshotCapabilities.Length != 0 ) )
{
videoDevice.ProvideSnapshots = true;
videoDevice.DesiredSnapshotSize = (Size) snapshotResolutionsCombo.SelectedItem;
videoDevice.SnapshotFrame += new NewFrameEventHandler( videoDevice_SnapshotFrame );
}

EnableConnectionControls( false );

videoSourcePlayer.VideoSource = videoDevice;
videoSourcePlayer.Start( );
}
}

// On "Disconnect" button clicked
private void disconnectButton_Click( object sender, EventArgs e )
{
Disconnect( );
}

// Disconnect from video device
private void Disconnect( )
{
if ( videoSourcePlayer.VideoSource != null )
{
// stop video device
videoSourcePlayer.SignalToStop( );
videoSourcePlayer.WaitForStop( );
videoSourcePlayer.VideoSource = null;

if ( videoDevice.ProvideSnapshots )
{
videoDevice.SnapshotFrame -= new NewFrameEventHandler( videoDevice_SnapshotFrame );
}

EnableConnectionControls( true );
}
}

// Simulate snapshot trigger
private void triggerButton_Click( object sender, EventArgs e )
{
if ( ( videoDevice != null ) && ( videoDevice.ProvideSnapshots ) )
{
videoDevice.SimulateTrigger( );
}
}

// New snapshot frame is available
private void videoDevice_SnapshotFrame( object sender, NewFrameEventArgs eventArgs )
{
Console.WriteLine( eventArgs.Frame.Size );

ShowSnapshot( (Bitmap) eventArgs.Frame.Clone( ) );
}

private void ShowSnapshot( Bitmap snapshot )
{
if ( InvokeRequired )
{
Invoke( new Action<Bitmap>( ShowSnapshot ), snapshot );
}
else
{
if ( snapshotForm == null )
{
snapshotForm = new SnapshotForm( );
snapshotForm.FormClosed += new FormClosedEventHandler( snapshotForm_FormClosed );
snapshotForm.Show( );
}

snapshotForm.SetImage( snapshot );
}
}

private void snapshotForm_FormClosed( object sender, FormClosedEventArgs e )
{
snapshotForm = null;
}
}
}
支持(0) 反对(0) 小小小白R | 园豆:102 (初学一级) | 2012-03-05 16:50

@小小小白R: 是哪个方法进行视频、图像捕获的?

支持(0) 反对(0) az235 | 园豆:8483 (大侠五级) | 2012-03-05 17:11

@az235: 

 videoSourcePlayer.VideoSource = videoDevice;
videoSourcePlayer.Start( );

这是哪个
AForge提供的控件
支持(0) 反对(0) 小小小白R | 园豆:102 (初学一级) | 2012-03-05 22:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册