1

目前我正在制作一个应用程序来从网络摄像头捕获视频,同时单击写入文本文件的各种按钮以在视频上做笔记。除了 WM_CAP_SEQUENCE 在捕获过程中默认取消对应用程序的控制之外,我现在几乎已经完成了所有工作......所以没有按下按钮。我需要传入一个捕获参数结构来告诉它允许单击,通过将 bool yField 设置为 true 来完成。这是我有点麻烦的地方,我不习惯结构,也不太了解如何使用 WM_CAP_SET_SEQUENCE_SETUP,我在下面发布相关代码,希望有人能给我一些见解或指示?

[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA", SetLastError = true)]
    public static extern int SendMessage2(IntPtr webcam1, int Msg, IntPtr wParam, ref CAPTUREPARMS lParam);


CAPTUREPARMS CaptureParams = new CAPTUREPARMS();
        CaptureParams.fYield = 1;
        CaptureParams.fAbortLeftMouse = 0;
        CaptureParams.fAbortRightMouse = 0;
        CaptureParams.dwRequestMicroSecPerFrame = 66667;
        CaptureParams.fMakeUserHitOKToCapture = 0;
        CaptureParams.wPercentDropForError = 10;
        CaptureParams.wChunkGranularity = 0;
        CaptureParams.dwIndexSize = 0;
        CaptureParams.wNumVideoRequested = 10;
        CaptureParams.fCaptureAudio = 0;
        CaptureParams.fLimitEnabled = 0;
        CaptureParams.fMCIControl = 0;
        CaptureParams.fStepMCIDevice = 0;
        CaptureParams.dwMCIStartTime = 0;
        CaptureParams.dwMCIStopTime = 0;
        CaptureParams.fStepCaptureAt2x = 0;
        CaptureParams.wStepCaptureAverageFrames = 5;
        CaptureParams.dwAudioBufferSize = 0;


SendMessage2(webcam1, WM_CAP_SET_SEQUENCE_SETUP, new IntPtr(Marshal.SizeOf(CaptureParams)), ref CaptureParams);

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
    public struct CAPTUREPARMS
    {
        public System.UInt32 dwRequestMicroSecPerFrame;
        public System.Int32 fMakeUserHitOKToCapture;
        public System.UInt32 wPercentDropForError;
        public System.Int32 fYield;
        public System.UInt32 dwIndexSize;
        public System.UInt32 wChunkGranularity;
        public System.Int32 fCaptureAudio;
        public System.UInt32 wNumVideoRequested;
        public System.UInt32 wNumAudioRequested;
        public System.Int32 fAbortLeftMouse;
        public System.Int32 fAbortRightMouse;
        public System.Int32 fMCIControl;
        public System.Int32 fStepMCIDevice;
        public System.UInt32 dwMCIStartTime;
        public System.UInt32 dwMCIStopTime;
        public System.Int32 fStepCaptureAt2x;
        public System.UInt32 wStepCaptureAverageFrames;
        public System.UInt32 dwAudioBufferSize;



        public void SetParams(System.Int32 fYield, System.Int32 fAbortLeftMouse, System.Int32 fAbortRightMouse, System.UInt32 dwRequestMicroSecPerFrame, System.Int32 fMakeUserHitOKToCapture,
            System.UInt32 wPercentDropForError, System.UInt32 dwIndexSize, System.UInt32 wChunkGranularity, System.UInt32 wNumVideoRequested, System.Int32 fCaptureAudio, System.Int32 fMCIControl,
            System.Int32 fStepMCIDevice, System.UInt32 dwMCIStartTime, System.UInt32 dwMCIStopTime, System.Int32 fStepCaptureAt2x, System.UInt32 wStepCaptureAverageFrames, System.UInt32 dwAudioBufferSize)
        {


            this.dwRequestMicroSecPerFrame = dwRequestMicroSecPerFrame;
            this.fMakeUserHitOKToCapture = fMakeUserHitOKToCapture;
            this.fYield = fYield;
            this.wPercentDropForError = wPercentDropForError;
            this.dwIndexSize = dwIndexSize;
            this.wChunkGranularity = wChunkGranularity;
            this.wNumVideoRequested = wNumVideoRequested;
            this.fCaptureAudio = fCaptureAudio;
            this.fAbortLeftMouse = fAbortLeftMouse;
            this.fAbortRightMouse = fAbortRightMouse;
            this.fMCIControl = fMCIControl;
            this.fStepMCIDevice = fStepMCIDevice;
            this.dwMCIStartTime = dwMCIStartTime;
            this.dwMCIStopTime = dwMCIStopTime;
            this.fStepCaptureAt2x = fStepCaptureAt2x;
            this.wStepCaptureAverageFrames = wStepCaptureAverageFrames;
            this.dwAudioBufferSize = dwAudioBufferSize;
4

1 回答 1

0

wParam必须等于结构的大小并且wParam是 before lParam,所以你应该这样称呼它:

SendMessage2(webcam1, WM_CAP_SET_SEQUENCE_SETUP, new IntPtr(Marshal.SizeOf(typeof(CAPTUREPARMS))), ref CaptureParams);

方法签名应如下所示:

[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")]
public static extern IntPtr SendMessage2(IntPtr webcam1, int Msg, IntPtr wParam, ref CAPTUREPARMS lParam);

您的结构也有错误的布局,请使用 pinvoke.net 中的CAPTUREPARMS定义(Pack=1虽然该部分在那里看起来很可疑,所以您可能想尝试使用和不使用它)。

于 2010-01-29T09:49:58.590 回答