日期:2014-05-17  浏览次数:21096 次

怎样释放掉摄像头占用的资源
有一个Winform下的摄像头使用实例,摄像头被封装成了一个控件,但是当项目第一次运行时正常,以后再次运行就会弹出窗口,如下:


大侠们说是没有释放掉摄像头占用的资源,小弟不懂啊,请问各位大侠应该怎样释放资源?

实例主要代码如下:
namespace WebCamPictureBox
{
    [Browsable(true), Description("WebCam PictureBox"), ToolboxBitmap(typeof(WebCamPictureBox), "WebPictureBox.jpg")]
    public class WebCamPictureBox : PictureBox
    {

        #region API Declarations
        [DllImport("user32", EntryPoint = "SendMessage")]
        public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

        [DllImport("avicap32.dll", EntryPoint = "capCreateCaptureWindowA")]
        public static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);

        #endregion


        #region API Constants
        public const int WM_CAP_CONNECT = 1034;
        public const int WM_CAP_DISCONNECT = 1035;
        public const int WM_CAP_GET_FRAME = 1084;
        public const int WM_CAP_COPY = 1054;
        #endregion


        #region Delegate
        public delegate void WebCamConnectStateChangingEventHandler(object sender, EventArgs e);
        public delegate void WebCamConnectStateChangedEventHandler(object sender, EventArgs e);
        #endregion


        #region Var
        private int _CapHwnd;
        private Timer _Timer = new Timer();
        private bool _bIsStart;
        private IDataObject _tempObj;
        #endregion



        #region Private Property
        /// <summary>
        /// Gets or sets a value indicating whether is started.
        /// </summary>
        /// <value><c>true</c> if is started; otherwise, <c>false</c>.</value>
        public bool m_bIsStarted
        {
&