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

20151123 임현수 업무일지 WIN32API #8 비트맵 이미지 뷰어

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

■ Win32 api


■ 이미지 뷰어

WCHAR ucValue[14][30];
  
  wsprintf(ucValue[0], TEXT("[%c%c]")
    , *(((unsigned char *)(&stBFHead)) + 0)
    , *(((unsigned char *)(&stBFHead)) + 1));
  wsprintf(ucValue[1], TEXT("[%d] Bytes"), stBFHead.bfSize);
  wsprintf(ucValue[2], TEXT("[%d] Bytes"), stBFHead.bfOffBits);
  wsprintf(ucValue[3], TEXT("[%d] Bytes"), stBFInfo.biSize);
  wsprintf(ucValue[4], TEXT("[%d] Pixel"), stBFInfo.biWidth);
  wsprintf(ucValue[5], TEXT("[%d] Pixel"), stBFInfo.biHeight);
  wsprintf(ucValue[6], TEXT("[%d]"), stBFInfo.biPlanes);
  wsprintf(ucValue[7], TEXT("[%d]"), stBFInfo.biBitCount);
  wsprintf(ucValue[8], TEXT("[%d]"), stBFInfo.biCompression);
  wsprintf(ucValue[9], TEXT("[%d] Bytes"), stBFInfo.biSizeImage);
  wsprintf(ucValue[10], TEXT("[%d]"), stBFInfo.biXPelsPerMeter);
  wsprintf(ucValue[11], TEXT("[%d]"), stBFInfo.biYPelsPerMeter);
  wsprintf(ucValue[12], TEXT("[%d]"), stBFInfo.biClrUsed);
  wsprintf(ucValue[13], TEXT("[%d]"), stBFInfo.biClrImportant);
▲ 비트맵 파일 정보 출력을 위한 작업


비트맵 이미지는 거꾸로 저장이 된다.
눈도 실제로 뒤집어서 보는 것을 뇌가 뒤집어서 보여주는 것이다.

NTSC 주사방식 미국,우리나라 Z식으로 찍는다.
PAL 유럽식     ㄷ식으로 찍는다.

도트프린터 방식이 그렇다. Z처럼 찍기.
동영상은 1초에 20~24장을 그렇게 찍는다.

캠코더로 모니터를 촬영해서 보면
모니터가 화면 점을 찍는 타이밍이 같지않으면 공백자리가 발생해서 까만색으로보인다.
주사방식이 겹치면서 발생하는 현상이다.

초고속카메라로 찍으면 점단위로 찍는게 보일 수도 있다.

■ 비트맵 로딩속도 향상

프로그램 실행 초기에 메모리를 좀써서 create에서 일을하고
나중에부터 memdc가 비트맵을 그리도록 한다.


LRESULT OnPaint(WPARAM wParam, LPARAM lParam)
{
  PAINTSTRUCT ps;
  HDC hdc;
  HDC MemDC;
  
  hdc = BeginPaint(hWnd, &ps);
  MemDC = CreateCompatibleDC(hdc);
  SelectObject(MemDC, Screen);

  BitBlt(hdc, XPOS, YPOS, stBFInfo.biWidth, stBFInfo.biHeight, MemDC, 00, SRCCOPY);
  
  DeleteDC(MemDC);
  EndPaint(hWnd, &ps);
  return 0;
}

void drawBMP(void)
{
  HDC hdc;
  HDC MemDC;

  int iCntX;
  int iCntY;
  
  hdc = GetDC(hWnd);
  Screen = CreateCompatibleBitmap(hdc, stBFInfo.biWidth, stBFInfo.biHeight);  // 비트맵을 생성
  MemDC = CreateCompatibleDC(hdc);
  SelectObject(MemDC, Screen); // Screen을 MemDC에 선택해준다. 즉 MemDC는 비트맵이 된다.
  
  for (iCntY = 0; iCntY < stBFInfo.biHeight; ++iCntY)
  {
    for (iCntX = 0; iCntX < stBFInfo.biWidth; ++iCntX)
    {
      SetPixel(MemDC, iCntX, (stBFInfo.biHeight - iCntY -1)
        , RGB(*(ucpData + (iCntY * stBFInfo.biWidth * 3) + (iCntX * 3) + 2 + iCntY*uiPad)
        , *(ucpData + (iCntY * stBFInfo.biWidth * 3) + (iCntX * 3) + 1 + iCntY*uiPad)
        , *(ucpData + (iCntY * stBFInfo.biWidth * 3) + (iCntX * 3) + 0 + iCntY*uiPad)));
    }
  }

  DeleteDC(MemDC);
  free(ucpData);
  ReleaseDC(hWnd, hdc);
  return;
}

 drawBMP함수에서 
Screen = CreateCompatibleBitmap(hdc, stBFInfo.biWidth, stBFInfo.biHeight); 
이미지 크기만큼 비트맵을 생성한다.

SelectObject(MemDC, Screen); 
비트맵 Screen을 MemDC에 선택하여 준다.
MemDC는 Screen에 이미지를 그리게되는 셈이다.

OnPaint함수에서 
SelectObject(MemDC, Screen);
Screen을 MemDC에 선택하여 주는데, Screen에는 이미지가 들어있다.

BitBlt(hdc, XPOS, YPOS, stBFInfo.biWidth, stBFInfo.biHeight, MemDC, 00, SRCCOPY);
MemDC를 hdc에 그려주는데 MemDC는 곧 Screen이므로, 이미지가 hdc에 그려진다.

728x90