0

Situation

A while ago, I found code snippets for webcam capturing and minimized it for what I really need - capturing images, that's all. No device selection, no async timers, I just needed to capture images.

Below is the code. It doesn't have any checks and I know it is not exactly how good code looks like, but I wouldn't post huge code snippets here anyway.

It used to work well, however, recently I tried to run it again and it didn't work although my webcam does indeed work fine with any other program.

public static class Webcam
{
    private static IntPtr Handle;

    public static void Start()
    {
        Handle = capCreateCaptureWindowA("WebCap", 0, 0, 0, 320, 240, 0, 0);
        SendMessage(Handle, 1034, 0, 0);
        SendMessage(Handle, 1074, 0, 0);
    }
    public static void Stop()
    {
        SendMessage(Handle, 1035, 0, 0);
    }
    public static Image CaptureFrame()
    {
        SendMessage(Handle, 1084, 0, 0);
        SendMessage(Handle, 1054, 0, 0);      // <--- returns 0
        return (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
    }

    [DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
    [DllImport("avicap32.dll")]
    private static extern IntPtr capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);
}

Environment

Operating System: Windows 8 x64
Used webcam: Logitech C910 (Drivers are properly installed)

Question: What is wrong with this code and why does it not work?

4

0 回答 0