BCB Components rotating around DirectX

Welcome to BCB-Tools.com Latest News

Development Tools Demo Applications Step-By-Step Tutorials Component Reference

Register Here Available Downloads

Frequently Asked Questions Discussion Forums Receive emails from BCB-Tools.com Send us some Feedback

Links to other sites Information about the BCB-Tools.com website


    FORUM MESSAGE
    Go to the Welcome Page
        FORUM MESSAGE

    You are reading a General forum message.

    Re: Something related to WebCam Capture

    Author: Israel Luengo

    Date Posted: 2004-12-17 08:58:57





    // We use the windows api

    capFileSaveDIB (hwndVideo, FileName);


    Code:

    //---------------------------------------------------------------------------
    /*
    * Copyright (c) Allan Petersen, 2001.
    * This is a tutorial for a simple capture system using the win32 api
    * for accessing your webcam
    *
    * (c) Copyright 2001, Allan Petersen
    * ALL RIGHTS RESERVED
    *
    * Contact Allan Petersen at <[email protected]> or visit
    * www.allanpetersen.com
    *
    */
    //---------------------------------------------------------------------------

    #include <vcl.h>
    #pragma hdrstop

    #include <stdio.h>
    #include "c_cap.h"
    #include "ServerVideo.h"

    //---------------------------------------------------------------------------
    #pragma package(smart_init)

    __fastcall TCap::TCap (HWND Handle)
    {
        // create video capture window
        ParentHandle = Handle;
        hwndVideo = capCreateCaptureWindow(
                        (LPSTR) "My Capture Window",
                        WS_CHILD | WS_VISIBLE,
                        0, 0, 300, 200,
                        frmServerVideo->panelCaptura->Handle,
                        (int) 0);

                  /*      w = capCreateCaptureWindow("Mi Video",
                        WS_CHILD | WS_VISIBLE,
                           1, 1, 320, 240,
                           Panel1->Handle, 0); */


        pStringCapDrivers = new TStringList;
        SelectedDevice = -1;
    }


    __fastcall TCap::~TCap ()
    {

        delete pStringCapDrivers;

        capPreview(hwndVideo, FALSE); // end preview
        capDriverConnect(hwndVideo, SelectedDevice);
        capDriverDisconnect(hwndVideo); // disconnect from driver
    }

    //---------------------------------------------------------------------------
    // enumerate the installed capture drivers
    //---------------------------------------------------------------------------
    int TCap::EnumCapDrv ()
    {
       char szDeviceName[80]; // driver name
       char szDeviceVersion[80]; // driver version
       char str[161]; // concatinated string
       int xcap; // counter

        xcap = 0;
        pStringCapDrivers->Clear ();
        do  {
            if (capGetDriverDescription(xcap, szDeviceName, sizeof(szDeviceName),
                               szDeviceVersion, sizeof(szDeviceVersion))){

                sprintf (str, "%s, %s", szDeviceName, szDeviceVersion);
                pStringCapDrivers->AddObject (str, (TObject *)xcap);
                }
            else {
                break;
                }
            xcap++;
            } while (true);

        return 0;
    }

    //---------------------------------------------------------------------------
    //  connecting to selected device and starts preview
    //---------------------------------------------------------------------------
    void TCap::Connect (int Selected)
    {
        CAPSTATUS CapStatus;
        int       hsize;

          // capDlgVideoDisplay(hwndVideo);
          // connect to the driver
        if (SelectedDevice != -1) {
            capPreview (hwndVideo, FALSE);
            capDriverConnect(hwndVideo, SelectedDevice);
            }

        if (!capDriverConnect(hwndVideo, Selected)) {
            // ---- Unable to connect to driver
            return;
            }

        // update the driver capabilities
        capDriverGetCaps (hwndVideo, sizeof(CAPDRIVERCAPS), &CapDrvCaps;);

        capDlgVideoFormat(ParentHandle);

        // Are there new image dimensions
        capGetStatus(hwndVideo, &CapStatus;, sizeof(CAPSTATUS));

        hsize = GetSystemMetrics(SM_CYMENU);
        hsize += GetSystemMetrics(SM_CYCAPTION);

        // ---- Rescaling the windows
        SetWindowPos(hwndVideo, NULL, 0, 0, CapStatus.uiImageWidth,
                    CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);
        SetWindowPos(ParentHandle, NULL, 0, hsize, CapStatus.uiImageWidth,
                    CapStatus.uiImageHeight+hsize, SWP_NOZORDER | SWP_NOMOVE);

        // set preview rate to 33.3 miliseconds, or 30 FPS
        capPreviewRate (hwndVideo, 33.3);

        // start preview video
        capPreview (hwndVideo, TRUE);

        // ---- Remember selected device
        SelectedDevice = Selected;
    }

    //---------------------------------------------------------------------------
    //  Get access to the video source format box
    //---------------------------------------------------------------------------
    void TCap::Format ()
    {
        int       hsize;

        CAPSTATUS CapStatus;

        capDlgVideoFormat(hwndVideo);
        // Are there new image dimensions
        capGetStatus(hwndVideo, &CapStatus;, sizeof(CAPSTATUS));

        hsize = GetSystemMetrics(SM_CYMENU);
        hsize += GetSystemMetrics(SM_CYCAPTION);

        SetWindowPos(ParentHandle, NULL, 0, hsize, CapStatus.uiImageWidth,
                    CapStatus.uiImageHeight+hsize, SWP_NOZORDER | SWP_NOMOVE);
        SetWindowPos(hwndVideo, NULL, 0, 0, CapStatus.uiImageWidth,
                    CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);
    }
    //---------------------------------------------------------------------------
    //  Get access to the video source dialog box
    //---------------------------------------------------------------------------
    void TCap::Source ()
    {
        capDlgVideoSource(hwndVideo);
    }

    //---------------------------------------------------------------------------
    //  capture a frame and save it
    //---------------------------------------------------------------------------
    void TCap::CaptureFrame (char *FileName)
    {
        capFileSaveDIB (hwndVideo, FileName);
    }




    Archivode cabecera

    C�digo:

    //---------------------------------------------------------------------------

    #ifndef c_capH
    #define c_capH
    //---------------------------------------------------------------------------
    #include <vfw.h> // video for windows library

    class TCap
    {
    private:

    protected:
        HWND ParentHandle;
        HWND hwndVideo;
        CAPDRIVERCAPS CapDrvCaps; // driver capabilities

        int     SelectedDevice;

    public:
        TStringList     *pStringCapDrivers;
        int EnumCapDrv();
        void Connect (int Selected);
        void Format ();
        void Source ();
        void CaptureFrame (char *FileName);
      __fastcall TCap(HWND Handle);
      __fastcall ~TCap();
    };


    #endif


    PD. Thanks to Allan Petersen for this code....personally i don't have time to check if it runs properly
    but it seems a good Starting Point.....Thanks again Allan




    REPLY TO THIS MESSAGE?
    Top    

    You can post a reply to this General message using the form below:
    Your Name:


    Message Subject:


    Message Body:


    Verification:





    When ready, click on the submit button below:






Top

Welcome |  Latest News |  Tools |  Demos |  Tutorials |  Reference |  Register |  Downloads
FAQ |  Forums |  Feedback |  Mailing List |  Links |  Site Information

This page is Copyright © 2007 Darren John Dwyer, Australia. All Rights Reserved.
Borland C++ Builder, CBuilder, etc are Trademarks of Borland Corporation.
DirectX, DirectDraw, Windows, etc are Trademarks of Microsoft Corporation.