locked
Video capture in BackgroundWorker RRS feed

  • Question

  • This might get a little long winded......

    So I've got this little tray application that can capture image from:

    1.  Local webcam via WIA
    2.  Network-enabled cam via a standard HTTP call / webClient
    3.  Locally attached video camera via avicap32.dll

    So, my app fires off a backgroundworker whenever it needs to capture an image.  I do this because I might need to wait a few seconds before my application can connect to whatever camera it's using because another application might still have a hanging connection to the camera.  I start a timer when I start the background worker and just keep trying to capture an image until the timer expires, or I get an image.  I just swallow any exceptions until the timer expires.  Anyways......

    So, this works very well for the web cam and the net cam.  My issue is with how avicap32.dll works.  It seems that you MUST have a "visible" component for it do draw it's preview image.

    What I tried was to create a local picturebox inside of my thread.  I then previewed the video stream to the local picturebox.  From what I can tell, the only way to get avicap32.dll to take a snapshot is to throw it a WM_CAP_EDIT_COPY.  It just copies the latest frame from the picturebox.

    Since the picturebox wasn't drawn anywhere, I guess it can't copy anything to the clipboard.  Does anyone know a way around this?

    Friday, June 9, 2006 4:34 PM

All replies

  • Hi

     

    You can copy it from the Clipboard with

    System.Windows.Forms.Clipboard.GetDataObject();

    After having called:

    User32.SendMessage(Devicehwnd, WM_CAP_EDIT_COPY, 0, 0); (API Used)

     

    But you have to take care that the Thread your are calling from is declared as STA:

    Thread.SetApartmentState(ApartmentState.STA);

    Otherwise you don't have access to the Clipboard;

     

    This is not at all proper, but it works without any errors.

     

    Greetings

    Hager Pascal

     

    http://www.aphager.com

    Thursday, June 21, 2007 10:27 AM