C/C++ Program to Take Selfie Picture Using USB Web Camera and Save it as PNG Image File on Local Disk Full Project For Beginners

  • Post author:
  • Post category:c++
  • Post comments:0 Comments

 

 

camera.c

 

 

// COMPILE ON A WINDOWS COMPILER 
// THAT CAN include windows.h 
// WE HAVE USED VISUAL C++ 2012 
// ANY VERSION CAN BE USED 
// ******standard headers ********** // 
#include "windows.h"

#include "vfw.h"

#include <cstdio>

#pragma comment(lib, "Vfw32.lib")

// ********************************** // 
int main()
{

  // create the preview window 
  HWND hCam = capCreateCaptureWindow (
   L"hoven",
   WS_CHILD,
   0, 0, 0, 0,
   ::GetDesktopWindow(), 0);

  // connect to the first camera 
  // for other cameras try index 
  // 1, 2, in place of the 0 below 
  if(capDriverConnect(hCam, 0))
  {

    capFileSaveDIB(hCam, L"shot.bmp");

    // the screenshot is in the current 
    // directory, usually the same 
    // where the exe is created by 
    // your compiler 
    printf("Saved as shot.bmp!");

  }

  else 
  {

    printf("Check camera?");

  }

  DestroyWindow(hCam);

  return 0;

}

Leave a Reply