본문 바로가기
코드

Cam

by umaking 2010. 8. 10.
 

#include <vcl.h>
#include <Vfw.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480

//---------------------------------------------------------------------------
HWND hWndCap;
BITMAPINFO bi;
LRESULT CALLBACK capVideoStreamCallback(HWND hWnd, LPVIDEOHDR lpVHdr)
{
	HBITMAP hb;
	HDC hDC;

	hDC = GetDC(Form1->Panel1->Handle);
	hb = CreateCompatibleBitmap(hDC, SCREEN_WIDTH, SCREEN_HEIGHT);

	SetDIBits(hDC, hb, 0, SCREEN_HEIGHT, lpVHdr->lpData, &bi, DIB_RGB_COLORS);

	BITMAP bm;
	HDC hMemDC;
	POINT pt;
	if(hb)
	{
		hMemDC = CreateCompatibleDC(hDC);
		SelectObject(hMemDC, hb);
		GetObject(hb, sizeof(BITMAP), (LPSTR)&bm);
		BitBlt(hDC, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, hMemDC, 0, 0, SRCCOPY);
		DeleteDC(hMemDC);
	}


	Rectangle(hDC, 100, 100, 120, 120);

	ReleaseDC(NULL, hDC);
	DeleteObject(hb);


	return (LRESULT)TRUE;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
	hWndCap = capCreateCaptureWindow("default_cam", WS_CHILD | WS_VISIBLE,
	0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Form1->Handle, 0);

	capSetCallbackOnFrame(hWndCap, capVideoStreamCallback);

	bool bReady = capDriverConnect(hWndCap, 0);
	if(bReady)
	{
		bool bOK;

		DWORD dwSize = capGetVideoFormatSize(hWndCap);
		capGetVideoFormat(hWndCap, &bi, dwSize);
		bOK = capPreviewRate(hWndCap, 67); //67ms = 15fps
		bOK = capPreview(hWndCap, true);
	}
}
//---------------------------------------------------------------------------

__fastcall TForm1::~TForm1()
{
	capPreview(hWndCap, false);
	DestroyWindow(hWndCap);
}

'코드' 카테고리의 다른 글

Swift프로젝트에 AFNetworking 의존성 추가하기.  (0) 2015.09.20
WebDAV (FireMonkey)  (0) 2014.06.27
unzip  (2) 2010.08.03
FindWindow  (0) 2010.07.13
SQLPLUS에서 SQL DDL Export  (0) 2009.11.11