修改后的代码:github
一、调用windows自身摄像头属性设置窗口
使用VideoCaptureDevice对象的DisplayPropertyPage(IntPtr parentWindow)方法即可,以下是从Aforge源码里找到的调用api方式:
///
/// Invokes a new property frame, that is, a property sheet dialog box.
///
///
/// Parent window of property sheet dialog box.
/// Horizontal position for dialog box.
/// Vertical position for dialog box.
/// Dialog box caption.
/// Number of object pointers in ppUnk.
/// Pointer to the objects for property sheet.
/// Number of property pages in lpPageClsID.
/// Array of CLSIDs for each property page.
/// Locale identifier for property sheet locale.
/// Reserved.
/// Reserved.
///
/// Returns S_OK on success.
///
[DllImport( "oleaut32.dll" )]
public static extern int OleCreatePropertyFrame(
IntPtr hwndOwner,
int x,
int y,
[MarshalAs( UnmanagedType.LPWStr )] string caption,
int cObjects,
[MarshalAs( UnmanagedType.Interface, ArraySubType = UnmanagedType.IUnknown )]
ref object ppUnk,
int cPages,
IntPtr lpPageClsID,
int lcid,
int dwReserved,
IntPtr lpvReserved );
二、通过代码自定义设置摄像头属性
aforge发布版只封装了对摄像头控制属性(缩放、焦点、曝光等)的设置方法,要想设置亮度、对比度这些属性,需要在源码上添加功能。
有三个文件,都是Video.DirectShow项目下的:IAMVideoProcAmp.cs,VideoCaptureDevice.cs,VideoProcAmpProperty.cs
IAMVideoProcAmp.cs声明了几个调用com对象的方法,放在Internals文件夹下
// AForge Direct Show Library
// AForge.NET framework
// http://www.aforgenet.com/framework/
//
// Copyright © AForge.NET, 2009-2013
// contacts@aforgenet.com
//
namespace AForge.Video.DirectShow.Internals
{
using System;
using System.Runtime.InteropServices;
///
/// The IAMVideoProcAmp interface controls camera settings such as brightness, contrast, hue,
/// or saturation. To obtain this interface, query the filter that controls the camera.
///
[ComImport,
Guid("C6E13360-30AC-11D0-A18C-00A0C9118956"),
Int