The camera


The camera

A camera can be attached to a computer to capture video. Most laptops include a video camera. In Windows 10, you must verify the "Private Settings" to allow the use of the camera.
Una cámara puede ser conectada a una computadora para capturar video. La mayoría de las laptops incluyen una video cámara. En Windows 10, usted debe verificar la "Configuración de Privacidad" para permitir el uso de la cámara.

Problem 1
Create a Wintempla Dialog application called MyCap to test a digital video camera. After creating the application, add a "Camera" control to the GUI. You must click on "Show All Controls in Toolbox" to see and insert the "Camera" control. Set the name of the control as shown. Insert three buttons, one to Capture, another one to Stop and one to Save an image. Insert a drop down list to select the device as shown. Select the "SelChange" event as shown.
Cree una aplicación de diálogo de Wintempla llamada MyCap para probar una cámara de video digital. Después de crear la aplicación, agregue un control de "Camera" a la GUI. Usted debe hacer clic en "Show All Controls in Toolbox" para ver e insertar el control de "Camera". Fije el nombre del control cómo se muestra. Inserte tres botones, una para capturar, otro para detener la captura y otro para guardar una imagen. Inserte una drop down list para seleccionar el dispositivo cómo se muestra. Seleccione el evento "SelChange" cómo se muestra.

MyCapGui

DropDownList

Step A
Edit the stdafx.h file as shown. Be sure to include the "Vfw.h" file after including "Wintempla.h" and before "WintemplaWin.h" as shown.
Edite el archivo stdafx.h cómo se muestra. Asegúrese de incluir el archivo "Vfw.h" después de incluir "Wintempla.h" y antes de "WintemplaWin.h" cómo se muestra.

stdafx.h
...
//
#include "Wintempla.h"
#include "Vfw.h"
#pragma comment(lib, "Vfw32.lib")
#include "WintemplaWin.h"
using namespace std;


Step B
Edit the files MyCap.h and MyCap.cpp.
Edite los archivos MyCap.h y MyCap.cpp.

MyCap.h
#pragma once //______________________________________ MyCap.h
#include "Resource.h"
class MyCap: public Win::Dialog
{
public:
     MyCap()
     {
     }
     ~MyCap()
     {
     }
     void Capture();
     ...
};


MyCap.cpp
...
void MyCap::Window_Open(Win::Event& e)
{
     //________________________________________________________ ddDevice: list video devices
     const size_t len = 128;
     wchar_t deviceName[len];
     wchar_t deviceVersion[len];
     wstring text;
     for (int i = 0; i < 10; i++)
     {
          if (::capGetDriverDescription(i, deviceName, len, deviceVersion, len) != TRUE) break;
          text = deviceName;
          text += L" (";
          text += deviceVersion;
          text += L")";
          ddDevice.Items.Add(text, i);
     }
     ddDevice.SelectedIndex = 0;
     cameraMain.Show(SW_SHOWNORMAL);
     cameraMain.Update();
}

void MyCap::btCapture_Click(Win::Event& e)
{
     Capture();
}

void MyCap::btStop_Click(Win::Event& e)
{
     cameraMain.Abort();
     cameraMain.Stop();
     cameraMain.Disconnect();
}

void MyCap::Capture()
{
     LPARAM device = 0;
     if (ddDevice.GetSelectedData(device) == false) return;
     if (cameraMain.Connect((int)device) == false)
     {
          this->MessageBox(L"Unable to connect to this device", L"MyCap", MB_OK | MB_ICONERROR);
     }
     cameraMain.SetPreview(true);
     cameraMain.SetPreviewRate(60);
     cameraMain.SetStrechFrames(false);
}

void MyCap::btSaveImage_Click(Win::Event& e)
{
     cameraMain.GrabFrame();
     cameraMain.CopyFrameBuffer();
     PAINTSTRUCT ps;
     HDC hdc = ::BeginPaint(cameraMain.GetHWND(), &ps);
     HDC hdcMem = ::CreateCompatibleDC(hdc);
     HBITMAP hBitmap = NULL;
     if (hdcMem != NULL)
     {
          if (::OpenClipboard(cameraMain.GetHWND()))
          {
               hBitmap = (HBITMAP)::GetClipboardData(CF_BITMAP);
               ::SelectObject(hdcMem, hBitmap);
               ::CloseClipboard();
               PBITMAPINFO pbi = cameraMain.CreateBitmapInfoStruct(hBitmap);
               Win::FileDlg dlg;
               dlg.Clear();
               dlg.SetFilter(L"Bitmap files (*.bmp)\0*.bmp\0\0", 0, L"bmp");
               if (dlg.BeginDialog(hWnd, L"Save", true) == TRUE)
               {
                    cameraMain.CreateBMPFile(dlg.GetFileNameFullPath(), pbi, hBitmap, hdcMem);
               }          
          }
     }
     Capture();
}


MyCapRun

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home