본문 바로가기
코스웨어/15년 스마트컨트롤러

20151124_안향진_API_9

by 알 수 없는 사용자 2015. 11. 24.
728x90
반응형

<캠>


=그래프 바탕 흰색으로 수정

PatBlt


BOOL PatBlt(HDC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, DWORD dwRop);



HBRUSH hBrWhite;


hBrWhite = CreateSolidBrush(RGB(255,255,255));

(HBRUSH)SelectObject(hdc,hBrWhite) ;


                

PatBlt(hdc,200,50,100,100,PATCOPY);







#include <windows.h>

#define
  XPOS  20
#define
 YPOS  20
#define
 SWIDTH  150
#define
 SHEIGHT 25
#define
 YGAP  5
#define
 XGAP  10

#define
 XGRAPH  256 // 0 ~ 255
#define
 YGRAPH  256
//#define GLOVAL

typedef
 struct _msgmap
{
  UINT uiMsg;
  LRESULT(*fp)(WPARAM, LPARAM);
}stMsgmap;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT OnDestroy( WPARAM, LPARAM);
LRESULT OnCreate( WPARAM, LPARAM);
LRESULT OnPaint( WPARAM, LPARAM);


stMsgmap Msgmap[] 
= {
  { WM_PAINT, OnPaint },
  { WM_DESTROY, OnDestroy },
  { WM_CREATE, OnCreate },
  { WM_NULL, 
0 }
};

HINSTANCE g_hInst;  
HWND hWnd;
LPSTR lpszClass 
= L"Viewer"; 
UCHAR *ucpData;
UINT uiPad;
UINT uiImgWidth;
UINT uiImgHeight;
UINT uiImgSize;

UINT uiSumR[
256];
UINT uiSumG[
256];
UINT uiSumB[
256];

#ifdef
 GLOVAL
HDC MemDC; 
// 전역으로 해도 동작은 됨
#endif

static
 HBITMAP MyBitmap;
static
 HBITMAP HistoBmp;

int
 APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance
  , LPSTR lpszCmdParam, 
int nCmdShow)
{
  MSG Message;
  WNDCLASS WndClass; 
  g_hInst 
= hInstance;  

  WndClass.cbClsExtra 
= 0;
  WndClass.cbWndExtra 
= 0;
  WndClass.hbrBackground 
= (HBRUSH)GetStockObject(WHITE_BRUSH); 
  WndClass.hCursor 
= LoadCursor(NULL, IDC_ARROW); 
  WndClass.hIcon 
= LoadIcon(NULL, IDI_APPLICATION);
  WndClass.hInstance 
= hInstance;
  WndClass.lpfnWndProc 
= (WNDPROC)WndProc;
  WndClass.lpszClassName 
= lpszClass;
  WndClass.lpszMenuName 
= NULL;
  WndClass.style 
= CS_HREDRAW | CS_VREDRAW;
  RegisterClass(
&WndClass);

  hWnd 
= CreateWindow(
    lpszClass,
    lpszClass, 
    (WS_CAPTION 
| WS_SYSMENU | WS_OVERLAPPED | WS_THICKFRAME /*| WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VSCROLL | WS_HSCROLL*/),
    CW_USEDEFAULT, CW_USEDEFAULT, 
1050800
    NULL, (HMENU)NULL, hInstance, NULL
    );
  ShowWindow(hWnd, nCmdShow); 

  
while (GetMessage(&Message, 000)) { 
    TranslateMessage(
&Message);
    DispatchMessage(
&Message); 
  }
  
return Message.wParam; 
}

LRESULT CALLBACK WndProc(HWND hWpWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
  stMsgmap *stpMap 
= Msgmap;
  hWnd 
= hWpWnd;
  
while (WM_NULL != (*stpMap).uiMsg)
  {
    
if (iMessage == (*stpMap).uiMsg)
    {
      
return (((*stpMap).fp)(wParam, lParam));
    }
    ++stpMap;
  }

  
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}

BOOL DrawBitmap(
void)
{
  HDC hdc;
  PAINTSTRUCT ps;
  INT iCntY;
  INT iCntX;

#ifndef
 GLOVAL
  HDC MemDC;

#endif

  UINT uiCnt[XGRAPH] 
= { 0, };
  UINT uiMaxVal;

  hdc 
= GetDC(hWnd);
    
  MyBitmap 
= CreateCompatibleBitmap(hdc, uiImgWidth, uiImgHeight);  
  MemDC 
= CreateCompatibleDC(hdc);

  SelectObject(MemDC, MyBitmap);  
  
  
for (iCntY = 0; iCntY < uiImgHeight; ++iCntY)
  {
    
for (iCntX = 0; iCntX < uiImgWidth; ++iCntX)
    {
      SetPixel(MemDC, iCntX, uiImgHeight - iCntY, RGB(
        
//SetPixel(hdc, iCntX, iCntY, RGB(
        *(ucpData + (
3 * (iCntY*uiImgWidth + iCntX)) + 2 + (iCntY*uiPad)),
        *(ucpData + (
3 * (iCntY*uiImgWidth + iCntX)) + 1 + (iCntY*uiPad)),
        *(ucpData + (
3 * (iCntY*uiImgWidth + iCntX)) + 0 + (iCntY*uiPad))));

      ++uiCnt[ucpData[
3 * ((iCntY*uiImgWidth) + (iCntX)) + 0 + (iCntY*uiPad)]]; // 히스토그램1
      ++uiCnt[ucpData[
3 * ((iCntY*uiImgWidth) + (iCntX)) + 1 + (iCntY*uiPad)]];
      ++uiCnt[ucpData[
3 * ((iCntY*uiImgWidth) + (iCntX)) + 2 + (iCntY*uiPad)]];
      
      
//++uiCnt[(ucpData[3 * ((iCntY*uiImgWidth) + (iCntX)) + 0 + (iCntY*uiPad)] + 
      
//    ucpData[3 * ((iCntY*uiImgWidth) + (iCntX)) + 1 + (iCntY*uiPad)] +
      
//    ucpData[3 * ((iCntY*uiImgWidth) + (iCntX)) + 2 + (iCntY*uiPad)])/3];

      
//ucpData[3*(iCnty*uiImgWidth + iCntX) + 2 + (iCntY*uiPad)],
      
//ucpData[3 * (iCnty*uiImgWidth + iCntX) + 1 + (iCntY*uiPad)],
      
//ucpData[3 * (iCnty*uiImgWidth + iCntX) + 0 + (iCntY*uiPad)],
      
//ucpData[(iCntY*uiImgWidth * 3) + (iCntX * 3) + 2 + (iCntY*uiPad)],
      
//ucpData[(iCntY*uiImgWidth * 3) + (iCntX * 3) + 1 + (iCntY*uiPad)],
      
//ucpData[(iCntY*uiImgWidth * 3) + (iCntX * 3) + 0 + (iCntY*uiPad)]));
    }
  }
  uiMaxVal 
= 0;
  
for (iCntX = 0; iCntX < XGRAPH; ++iCntX)
  {  
    uiCnt[iCntX] 
= uiCnt[iCntX]/3; 
    
if (uiMaxVal < uiCnt[iCntX])
    {
      uiMaxVal 
= uiCnt[iCntX];
    }
  }

  
for (iCntX = 0; iCntX < XGRAPH; ++iCntX)
  {
    uiCnt[iCntX] 
= (uiCnt[iCntX] * YGRAPH) / uiMaxVal; // (uiCnt[iCntX]/ uiMaxVal) * 255  : 오차줄이기
  }
    

#ifndef
 GLOVAL
  DeleteDC(MemDC);

#endif

  HistoBmp 
= CreateCompatibleBitmap(hdc, XGRAPH + 1, YGRAPH);

  MemDC 
= CreateCompatibleDC(hdc);

  SelectObject(MemDC, HistoBmp);
  PatBlt(MemDC, 
00, XGRAPH + 1, YGRAPH, WHITENESS);
  
for (iCntY = 0; iCntY < YGRAPH; ++iCntY)
  {
    
for (iCntX = 0; iCntX < XGRAPH ; ++iCntX)
    {
      
if ((YGRAPH-1-iCntY) <= uiCnt[iCntX])
      {
        SetPixel(MemDC, iCntX+
1, iCntY, RGB(000));  // 그래프
      }
    }
    SetPixel(MemDC, 
0, iCntY, RGB(000)); // 세로축
  }

#ifndef
 GLOVAL
  DeleteDC(MemDC);

#endif

  ReleaseDC(hWnd, hdc);
  free(ucpData);
  
return TRUE;
}

LRESULT OnPaint(WPARAM wParam, LPARAM lParam)
{
  HDC hdc;

#ifndef
 GLOVAL
  HDC MemDC; 
// 전역으로 해도 동작은 됨
#endif

  PAINTSTRUCT ps;

  hdc 
= BeginPaint(hWnd, &ps);
#ifndef
 GLOVAL
  MemDC 
= CreateCompatibleDC(hdc);
  SelectObject(MemDC, MyBitmap);

#endif

  BitBlt(hdc, 
00, uiImgWidth, uiImgHeight, MemDC, 00, SRCCOPY);


#ifndef
 GLOVAL
  DeleteDC(MemDC);

#endif


#ifndef
 GLOVAL
  MemDC 
= CreateCompatibleDC(hdc);
  SelectObject(MemDC, HistoBmp);

#endif

  BitBlt(hdc, XPOS + uiImgWidth + 
2 * (SWIDTH + XGAP), 0, XGRAPH + 1, YGRAPH, MemDC, 00, SRCCOPY);

#ifndef
 GLOVAL
  DeleteDC(MemDC);

#endif

  
  EndPaint(hWnd, 
&ps);
  
return 0;
}

LRESULT OnDestroy(WPARAM wParam, LPARAM lParam)
{  
  
//free(ucpData);
#ifdef
 GLOVAL
  DeleteDC(MemDC);

#endif

  PostQuitMessage(
0);
  
return 0;
}

void
 PrintBmpInfo(BITMAPFILEHEADER *stpFH, BITMAPINFOHEADER *stpIH)
{
  UINT uiYCnt;

  WCHAR *ucTitle[] 
= {
    L"Magic Number:
", 
    L"
파일크기:",
    L"
데이터 오프셋:",
    L"
Info 헤더사이즈:",
    L"
가로:",
    L"
세로:",
    L"
비트 플레인:",
    L"
픽셀당 비트:",
    L"
압축 유형:",
    L"
데이터 크기:",
    L"
수평 해상도:",
    L"
수직 해상도:",
    L"
사용 칼라인덱스 수:",
    L"
중요 칼라인덱스 수:"
  };

  WCHAR ucValue[14][30];

  wsprintf(ucValue[0], L"
[%c][%c]", *(((unsigned char *)(stpFH)) + 0), *(((unsigned char *)(stpFH)) + 1));
  wsprintf(ucValue[1], L"
%d Bytes", stpFH->bfSize);
  wsprintf(ucValue[
2], L"%d", stpFH->bfOffBits);
  wsprintf(ucValue[
3], L"%d", stpIH->biSize);
  wsprintf(ucValue[
4], L"%d pixel", stpIH->biWidth);
  wsprintf(ucValue[
5], L"%d pixel", stpIH->biHeight);
  wsprintf(ucValue[
6], L"%d", stpIH->biPlanes);
  wsprintf(ucValue[
7], L"%d", stpIH->biBitCount);
  
switch (stpIH->biCompression)
  {
    
case 0:
      wsprintf(ucValue[
8], L"[BI_RGB]");
      break;
    case 1:
      wsprintf(ucValue[8], L"
[BI_RLE8]");
      break;
    case 2:
      wsprintf(ucValue[8], L"
[BI_RLE4]");
      break;
    case 3:
      wsprintf(ucValue[8], L"
[BI_BITFIELDS]");
      break;
    default:
      break;
  }
  
  wsprintf(ucValue[9], L"
%d Bytes", stpIH->biSizeImage);
  wsprintf(ucValue[
10], L"%d", stpIH->biXPelsPerMeter);
  wsprintf(ucValue[
11], L"%d", stpIH->biYPelsPerMeter);
  wsprintf(ucValue[
12], L"%d", stpIH->biClrUsed);
  wsprintf(ucValue[
13], L"%d", stpIH->biClrImportant);

  
for (uiYCnt = 0; uiYCnt < 14; ++uiYCnt)
  {  
    CreateWindow(L"
static", ucTitle[uiYCnt], WS_CHILD | WS_VISIBLE | ES_RIGHT,
      XPOS + stpIH-
>biWidth, YPOS + ((SHEIGHT + YGAP)*uiYCnt), SWIDTH, SHEIGHT, hWnd, (HMENU)-1, g_hInst, NULL);
    
    CreateWindow(L"edit", ucValue[uiYCnt], WS_CHILD 
| WS_VISIBLE | WS_BORDER | ES_READONLY | ES_CENTER,
      XPOS + stpIH-
>biWidth + SWIDTH + XGAP, YPOS + ((SHEIGHT + YGAP)*uiYCnt), SWIDTH, SHEIGHT, hWnd, (HMENU)-1, g_hInst, NULL);

  }
  
return;
}

LRESULT OnCreate(WPARAM wParam, LPARAM lParam)
{
  HDC hdc;

  HANDLE hFile;

  BITMAPFILEHEADER stBFHead;
  BITMAPINFOHEADER stBFInfo;
  BOOL bRet;
  DWORD dwCnt;

  hFile 
= CreateFile(L"1.bmp", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  
if (INVALID_HANDLE_VALUE == hFile)
  {
    MessageBox(hWnd, L"Open Error", L"ERROR", MB_OK);
    PostQuitMessage(
0);
    
return 0;
  }

  bRet 
= ReadFile(hFile, &stBFHead, sizeof(BITMAPFILEHEADER), &dwCnt, NULL);
  
if (FALSE == bRet)
  {
    MessageBox(hWnd, L"File헤더 Read Error", L"ERROR", MB_OK);
    CloseHandle(hFile);
    PostQuitMessage(
0);
    
return 0;
  }

  bRet 
= ReadFile(hFile, &stBFInfo, sizeof(BITMAPINFOHEADER), &dwCnt, NULL);
  
if (FALSE == bRet)
  {
    MessageBox(hWnd, L"Info헤더 Read Error", L"ERROR", MB_OK);
    CloseHandle(hFile);
    PostQuitMessage(
0);
    
return 0;
  }
  uiPad 
= stBFInfo.biWidth % 4;// padding 추출
  uiImgWidth 
= stBFInfo.biWidth;
  uiImgHeight 
= stBFInfo.biHeight;
  uiImgSize 
= stBFInfo.biSizeImage;
  PrintBmpInfo(
&stBFHead, &stBFInfo);
  
  ucpData 
= malloc(stBFInfo.biSizeImage);
  
if (0 == ucpData)
  {
    MessageBox(hWnd, L"Malloc Error", L"ERROR", MB_OK);
    CloseHandle(hFile);
    PostQuitMessage(
0);
    
return 0;
  }

  bRet 
= ReadFile(hFile, ucpData, stBFInfo.biSizeImage, &dwCnt, NULL);
  
if (FALSE == bRet)
  {
    MessageBox(hWnd, L"Image Data Read Error", L"ERROR", MB_OK);
    CloseHandle(hFile);
    free(ucpData);
    PostQuitMessage(
0);
    
return 0;
  }

  bRet 
= DrawBitmap();
  
if (FALSE == bRet)
  {
    MessageBox(hWnd, L"Draw Failed", L"ERROR", MB_OK);
    CloseHandle(hFile);
    free(ucpData);

#ifdef
 GLOVAL
    DeleteDC(MemDC);

#endif

    PostQuitMessage(
0);
    
return 0;
  }
  CloseHandle(hFile);
  
return 0;
}

=추가적으로 구성하시오..

원본 히스토 내용 히스토그램 1, 2


=실시간 그래프

함수사용이 좀 더 빠름





= VfW(Video for Windows)


1. 소스 추가


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



2. Project -> property





=캠 작동

=에러 처리



 LRESULT On_Paint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  HDC hdc;
  PAINTSTRUCT ps;  

  hdc 
= BeginPaint(hWnd, &ps);

  EndPaint(hWnd, 
&ps);
  
return 0;
}

LRESULT On_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
  HDC hdc;
  BITMAPINFO stBmpInfo;
  BOOL bRet;

  hCam 
= capCreateCaptureWindow(L"스마트", WS_CHILD | WS_VISIBLE, 0, 0, XSCALE, YSCALE, hWnd,0);

  if (NULL 
== hCam)
  {
    MessageBox(hWnd, L"
창을 생성할 수 없습니다", L"Error", MB_OK);
    PostQuitMessage(
0);
    
return;
  }

  bRet 
= capDriverConnect(hCam, 0);
  
if (FALSE == bRet)
  {
    MessageBox(hWnd, L"카메라를 찾을 수 없습니다.
", L"Error", MB_OK);
    PostQuitMessage(
0);
    
return;
  }
  
  capPreviewRate(hCam, 
1);
  capGetVideoFormat(hCam, 
&stBmpInfo, sizeof(BITMAPINFO));

  stBmpInfo.bmiHeader.biWidth 
= XSCALE;
  stBmpInfo.bmiHeader.biHeight 
= YSCALE;
  capSetVideoFormat(hCam, 
&stBmpInfo, sizeof(BITMAPINFO));

  capPreview(hCam, TRUE);
  
  
//capDriverDisconnect()
  //capSetCallbackOnFrame()

  return 0;
}




=콜백함수(Capture함수) 등록

capSetCallbackOnFrame(hCam, Capture); // capPreview 위에 
capPreview(hCam, TRUE);
/* video data block header */
typedef struct videohdr_tag {
  LPBYTE      lpData;                 
/* pointer to locked data buffer */
  DWORD       dwBufferLength;         /* Length of data buffer */
  DWORD       dwBytesUsed;            /* Bytes actually used */
  DWORD       dwTimeCaptured;         /* Milliseconds from start of stream */
  DWORD_PTR   dwUser;                 /* for client's use */
  DWORD       dwFlags;                /* assorted flags (see defines) */
  DWORD_PTR   dwReserved[4];          /* reserved for driver */
} VIDEOHDR, NEAR *PVIDEOHDR, FAR * LPVIDEOHDR;





BOOL StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, DWORD dwRop);




=원본데이터 수정




=실시간 그래프 가능


=이미지 사이즈 출력




데이터사이즈/ (가로*세로) = >RGB (3bytes)




=원본 데이터를 버퍼에 복사하여 복사본을 수정하여 출력






#include <windows.h>
#include
 <vfw.h>

//#pragma comment(lib, "vfw32.lib")


#define
 XSCALE 320
#define
 YSCALE 240

HWND hCam;
BITMAPINFO stBmpInfo;

typedef
 struct
{
  UINT uiMSG;
  LRESULT(*fp) (WPARAM, LPARAM);

}stMSG_Map;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

LRESULT On_Paint(WPARAM wParam, LPARAM lParam);
LRESULT On_Create(WPARAM wParam, LPARAM lParam);
LRESULT On_Destroy(WPARAM wParam, LPARAM lParam);
LRESULT capture(HWND, LPVIDEOHDR);

HINSTANCE g_hInst;
LPSTR lpszClass 
= L"캠";

stMSG_Map stMap[] 
= {
  { WM_PAINT, On_Paint },
  { WM_CREATE, On_Create },
  { WM_DESTROY, On_Destroy },
  { WM_NULL, 0 }
};

HWND hWnd;

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance
  , LPSTR lpszCmdParam, int nCmdShow)
{
  MSG Message;
  WNDCLASS WndClass;
  g_hInst 
= hInstance;

  WndClass.cbClsExtra 
= 0;
  WndClass.cbWndExtra 
= 0;
  WndClass.hbrBackground 
= (HBRUSH)GetStockObject(WHITE_BRUSH);
  WndClass.hCursor 
= LoadCursor(NULL, IDC_ARROW);
  WndClass.hIcon 
= LoadIcon(NULL, IDI_APPLICATION);
  WndClass.hInstance 
= hInstance;
  WndClass.lpfnWndProc 
= (WNDPROC)WndProc;
  WndClass.lpszClassName 
= lpszClass;
  WndClass.lpszMenuName 
= NULL;
  WndClass.style 
= CS_HREDRAW | CS_VREDRAW;
  RegisterClass(
&WndClass);

  hWnd 
= CreateWindow(lpszClass, lpszClass, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    NULL, (HMENU)NULL, hInstance, NULL);
  ShowWindow(hWnd, nCmdShow);

  while (GetMessage(
&Message, 0, 0, 0)) {
    TranslateMessage(
&Message);
    DispatchMessage(
&Message);
  }
  return Message.wParam;
}

LRESULT CALLBACK WndProc(HWND hWpWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
  hWnd 
= hWpWnd;
  stMSG_Map * stpMap 
= stMap;

  while (WM_NULL !
= ((*stpMap).uiMSG))
  {
    if (iMessage 
== ((*stpMap).uiMSG))
    {
      return (((*stpMap).fp)(wParam, lParam));
    }
    ++stpMap;
  }

  return (DefWindowProc(hWnd, iMessage, wParam, lParam));
}

LRESULT On_Paint(WPARAM wParam, LPARAM lParam)
{
  HDC hdc;
  PAINTSTRUCT ps;  

  hdc 
= BeginPaint(hWnd, &ps);

  EndPaint(hWnd, 
&ps);
  return 0;
}

#if 0
/* video data block header */
typedef struct videohdr_tag {
  LPBYTE      lpData;                 /* pointer to locked data buffer */
  DWORD       dwBufferLength;         /* Length of data buffer */
  DWORD       dwBytesUsed;            /* Bytes actually used */
  DWORD       dwTimeCaptured;         /* Milliseconds from start of stream */
  DWORD_PTR   dwUser;                 /* for client's use */
  DWORD       dwFlags;                /* assorted flags (see defines) */
  DWORD_PTR   dwReserved[4];          /* reserved for driver */
} VIDEOHDR, NEAR *PVIDEOHDR, FAR * LPVIDEOHDR;
#endif

LRESULT Capture(HWND hWpWnd, LPVIDEOHDR lpVHdr)
{
  HDC hdc;
  UINT uiXCnt;
  UINT uiYCnt;

  static BYTE Vdata[XSCALE*YSCALE*3];
  //WCHAR wcBuf[20] 
= { 0, };


  hdc 
= GetDC(hWnd);
  //wsprintf(wcBuf, L"
%u", lpVHdr->dwBufferLength);
  
//SetWindowText(hWnd, wcBuf);
  memcpy(Vdata, lpVHdr-
>lpData, lpVHdr->dwBufferLength);

  
for (uiYCnt = 0; uiYCnt < YSCALE; ++uiYCnt)
  {
    
for (uiXCnt = 0; uiXCnt < XSCALE; ++uiXCnt)
    {
      
//*( Vdata+ 3 * (uiYCnt*XSCALE + uiXCnt) + 0) = 0;
      *(Vdata + 
3 * (uiYCnt*XSCALE + uiXCnt) + 1= 0;
      *(Vdata + 
3 * (uiYCnt*XSCALE + uiXCnt) + 2= 0;
    }
  }

  StretchDIBits(hdc, XSCALE + 
200, XSCALE, YSCALE, 00, XSCALE, YSCALE, Vdata, &stBmpInfo, DIB_RGB_COLORS, SRCCOPY);

  memcpy(Vdata, lpVHdr-
>lpData, lpVHdr->dwBufferLength);

  
for (uiYCnt = 0; uiYCnt < YSCALE; ++uiYCnt)
  {
    
for (uiXCnt = 0; uiXCnt < XSCALE; ++uiXCnt)
    {
      *( Vdata+ 
3 * (uiYCnt*XSCALE + uiXCnt) + 0= 0;
      
//*(Vdata + 3 * (uiYCnt*XSCALE + uiXCnt) + 1) = 0;
      *(Vdata + 
3 * (uiYCnt*XSCALE + uiXCnt) + 2= 0;
    }
  }

  StretchDIBits(hdc, 
0, YSCALE +20 , XSCALE, YSCALE, 00, XSCALE, YSCALE, Vdata, &stBmpInfo, DIB_RGB_COLORS, SRCCOPY);

  memcpy(Vdata, lpVHdr-
>lpData, lpVHdr->dwBufferLength);

  
for (uiYCnt = 0; uiYCnt < YSCALE; ++uiYCnt)
  {
    
for (uiXCnt = 0; uiXCnt < XSCALE; ++uiXCnt)
    {
      *(Vdata + 
3 * (uiYCnt*XSCALE + uiXCnt) + 0= 0;
      *(Vdata + 
3 * (uiYCnt*XSCALE + uiXCnt) + 1= 0;
      
//*(Vdata + 3 * (uiYCnt*XSCALE + uiXCnt) + 2) = 0;
    }
  }

  StretchDIBits(hdc, XSCALE + 
20, YSCALE + 20, XSCALE, YSCALE, 00, XSCALE, YSCALE, Vdata, &stBmpInfo, DIB_RGB_COLORS, SRCCOPY);

  ReleaseDC(hWpWnd, hdc);
  
return 0;
}

LRESULT On_Create(WPARAM wParam, LPARAM lParam)
{
  HDC hdc;  
  BOOL bRet;

  hCam 
= capCreateCaptureWindow(L"스마트", WS_CHILD | WS_VISIBLE, 0, 0, XSCALE, YSCALE, hWnd,0);

  if (NULL 
== hCam)
  {
    MessageBox(hWnd, L"
창을 생성할 수 없습니다", L"Error", MB_OK);
    PostQuitMessage(
0);
    
return 0;
  }

  bRet 
= capDriverConnect(hCam, 0);
  
if (FALSE == bRet)
  {
    MessageBox(hWnd, L"카메라를 찾을 수 없습니다.
", L"Error", MB_OK);
    PostQuitMessage(
0);
    
return 0;
  }
  
  capPreviewRate(hCam, 
1);
  capGetVideoFormat(hCam, 
&stBmpInfo, sizeof(BITMAPINFO));

  stBmpInfo.bmiHeader.biWidth 
= XSCALE;
  stBmpInfo.bmiHeader.biHeight 
= YSCALE;
  capSetVideoFormat(hCam, 
&stBmpInfo, sizeof(BITMAPINFO));
  
  capSetCallbackOnFrame(hCam, Capture);
  capPreview(hCam, TRUE);
  
  hdc 
= GetDC(hWnd);
  ReleaseDC(hWnd, hdc);

  
return 0;
}

LRESULT On_Destroy(WPARAM wParam, LPARAM lParam)
{
  capDriverDisconnect(hCam);
  PostQuitMessage(
0);
  
return 0;
}


728x90