728x90
반응형
<Win32API>✔
================================================================
<비트맵 파일 뷰어>
void print_Bmp_Info(BITMAPFILEHEADER * stfH , BITMAPINFOHEADER * stiH , BITMAPFILEHEADER stBfhead , BITMAPINFOHEADER stBfInfo )
{
UINT iyCnt;
HWND hHandle;
TCHAR *ucTitle[] =
{
TEXT( "MAGIC NUM")
, TEXT( "Size of File")
, TEXT( "Data Position")
, TEXT( "Size of BITMAPINFOHEADER")
, TEXT( "Width of Image")
, TEXT( "Height of Image")
, TEXT( "Bit Plane Number")
, TEXT( "Bit Count")
, TEXT( "Compression")
, TEXT( "Size of Image")
, TEXT( "Resolution of Width")
, TEXT( "Resolution of Height")
, TEXT( "Number of Used Color")
, TEXT( "Index of Important Color")
};
TCHAR *ucValue[14][30];
iyCnt = 0;
wsprintf(ucValue[0], TEXT( "[%c%c]"),
*(((unsigned char *)(&stBfhead )) + 0), *(((unsigned char *)(&stBfhead )) + 1));
wsprintf(ucValue[1], TEXT( "[%d]"), stBfhead .bfSize);
wsprintf(ucValue[2], TEXT( "[%d]"), stBfhead .bfOffBits);
wsprintf(ucValue[3], TEXT( "[%d]"), stBfInfo .biSize);
wsprintf(ucValue[4], TEXT( "[%d] Pexel"), stBfInfo .biWidth);
wsprintf(ucValue[5], TEXT( "[%d] Pexel"), 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] Byte"), stBfInfo .biSizeImage);
wsprintf(ucValue[10], TEXT( "[%d] Pexel"), stBfInfo .biXPelsPerMeter);
wsprintf(ucValue[11], TEXT( "[%d] Pexel"), stBfInfo .biYPelsPerMeter);
wsprintf(ucValue[12], TEXT( "[%d]"), stBfInfo .biClrUsed);
wsprintf(ucValue[13], TEXT( "[%d]"), stBfInfo .biClrImportant);
for (iyCnt = 0; iyCnt < 14; iyCnt++)
{
CreateWindow(TEXT ("static" ), ucTitle[iyCnt]
, WS_CHILD | WS_VISIBLE
, XPOS, ( YPOS*(iyCnt+1)) + YGAP*iyCnt, SW, SH
, hWnd, ( HMENU)-1, g_hInst, NULL);
hHandle = CreateWindow(TEXT ("static" ), ucValue[iyCnt]
, WS_CHILD | WS_VISIBLE
, XPOS + SW + XGAP, ( YPOS*(iyCnt + 1)) + YGAP*iyCnt, SW, SH
, hWnd, ( HMENU)-1, g_hInst, NULL);
}
return;
}
* 사람의 눈은 실제로 뒤집어서 보는 것을 뇌가 뒤집어서 보여준다. 위에서부터 읽는 것을 아래부터 찍어준다.
- UI는 좌표값 작업이다. 좌표를 잘찾으면 된다.
- 저장하는 자료구조와 화면에 출력되는 구조는 다르다.
- 우리가 보는 화면을 주사한다 = 화면에 점을찍는다.
- NTSC방식: 우리나라.Z식으로 찍음
- PAL : 유럽식 ㄷ식으로 찍음
- 화면을 어떻게 찍을지?
- 리틀엔디언 , 빅엔디언은 하나가 될수 없다. 방식마다 다르기 때문에
- NTSC방식
- 1초에 한장씩 지그제그 방식으로 화면에 점이 찍히고 있다. 화면을 찍어 사진을 보면 검은 줄이 가있다.
- 주사 방식이 겹치면서 일이나는(점이 덜찍혔는데 화면에 나타난다)
- 주사방식에 = 주사방식이 겹치고, 동일한 좌표에 줄이 간것이 아니기 때문에 줄이 겹쳐서 검은 줄이 보이는 것.
..회전은 우리가 알아서 할것,
먼저 메모리를 사용하고 나중에 MemDC가 비트맵을 그린다. 멤디시에 쓴게 스크린으로 들어간다.
Screen = CreateCompatibleBitmap(hdc, stBfInfo.biwidth, stBfInfo.biHeight);
화면과 동급크기의 비트맵이 만들어진다.
SelectObject(MemDC, Screen);
- MemDC가 Screen에 이미지를 그림.
*OnPaint()
SelectObject(MemDC, Screen);
- 이미지가 Screen에 들어있고 MemDC가 선택한다.
BitBlt(hdc, XPOS, YPOS,stBfInfo.biwidth, stBfInfo.biHeight, MemDC, 0,0, SRCCOPY);
-MemDC를 hd이미지를 그린다.
✔ 인수
- hdc:DC핸들
- hgdiobj:DC에 선택하고자 하는 GDI 오브젝트의 핸들.
이 오브젝트는 CreatePen, CreateSolidBrush, CreateFont 등의 함수로 생성한 오브젝트이거나 GetStockObject로 구한 스톡 오브젝트여야 한다.
✔ 리턴
이전에 선택되어 있던 같은 종류의 GDI 오브젝트의 핸들이 리턴된다.
단 선택한 오브젝트가 리전인 경우 리턴값을 다음 셋 중 하나가 된다.
리턴값 | 설명 |
SIMPLEREGION | 리전은 하나의 사각형으로 구성되어 있다. |
COMPLEXREGION | 리전은 하나 이상의 사각형으로 구성되어 있다. |
NULLREGION | 리전이 비어있다. |
에러 발생시 NULL이 리턴된다.
✔ 설명
GDI는 그래픽 출력에 사용되는 도구이며 펜, 브러시, 비트맵, 리전, 패스, 팔레트, 폰트 등등이 있다.
그리기에 사용할 GDI 오브젝트를 변경하고자 할 때 이 오브젝트를 만든 후 이 함수로 DC에 선택해 주어야 한다.
* DeleteObject(SelectObject(hdc,OldBrush));
- SelectObject 함수가 이전에 선택되어 있던 같은 타입의 GDI 오브젝트를 리턴해 주기 때문에 리턴되는 브러시를 DeleteObject 함수로 삭제하였다.
CreateCompatibleDC
void print_Bmp_Info(BITMAPFILEHEADER * stfH , BITMAPINFOHEADER * stiH )
{
UINT iyCnt;
HWND hHandle;
TCHAR *ucTitle[] =
{
TEXT( "MAGIC NUM")
, TEXT( "Size of File")
, TEXT( "Data Position")
, TEXT( "Size of BITMAPINFOHEADER")
, TEXT( "Width of Image")
, TEXT( "Height of Image")
, TEXT( "Bit Plane Number")
, TEXT( "Bit Count")
, TEXT( "Compression")
, TEXT( "Size of Image")
, TEXT( "Resolution of Width")
, TEXT( "Resolution of Height")
, TEXT( "Number of Used Color")
, TEXT( "Index of Important Color")
};
TCHAR *ucValue[14][30];
iyCnt = 0;
wsprintf(ucValue[0], TEXT( "[%c%c]"), *(((unsigned char *)(&stBfhead)) + 0), *(((unsigned char *)(&stBfhead)) + 1));
wsprintf(ucValue[1], TEXT( "[%d]"), stBfhead.bfSize);
wsprintf(ucValue[2], TEXT( "[%d]"), stBfhead.bfOffBits);
wsprintf(ucValue[3], TEXT( "[%d]"), stBfInfo.biSize);
wsprintf(ucValue[4], TEXT( "[%d] Pexel"), stBfInfo.biWidth);
wsprintf(ucValue[5], TEXT( "[%d] Pexel"), 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] Byte"), stBfInfo.biSizeImage);
wsprintf(ucValue[10], TEXT( "[%d] Pexel"), stBfInfo.biXPelsPerMeter);
wsprintf(ucValue[11], TEXT( "[%d] Pexel"), stBfInfo.biYPelsPerMeter);
wsprintf(ucValue[12], TEXT( "[%d]"), stBfInfo.biClrUsed);
wsprintf(ucValue[13], TEXT( "[%d]"), stBfInfo.biClrImportant);
for (iyCnt = 0; iyCnt < 14; iyCnt++)
{
CreateWindow(TEXT ("static" ), ucTitle[iyCnt]
, WS_CHILD | WS_VISIBLE
, XPOS + stBfInfo.biWidth + XGAP , ( YPOS*(iyCnt + 1)) + YGAP*iyCnt, SW , SH
, hWnd, ( HMENU)-1, g_hInst, NULL);
hHandle = CreateWindow(TEXT ("static" ), ucValue[iyCnt]
, WS_CHILD | WS_VISIBLE
, ( XPOS+stBfInfo.biWidth) + XGAP + SW + XGAP, ( YPOS*(iyCnt + 1)) + YGAP*iyCnt, SW , SH
, hWnd, ( HMENU)-1, g_hInst, NULL);
}
return;
}
LRESULT OnPaint( WPARAM wParam , LPARAM lParam )
{
//HBITMAP myB, oldB;
PAINTSTRUCT ps;
HDC hdc; //<
HDC MemDC; //<
hdc = BeginPaint(hWnd, &ps);
HPEN myPen;
myPen = CreatePen( PS_DOT, 5, RGB(255, 0, 0));
MemDC = CreateCompatibleDC(hdc); //<
SelectObject(MemDC, Screen); //<
BitBlt(hdc, XPOS, YPOS, stBfInfo.biWidth, stBfInfo.biHeight, MemDC, 0, 0, SRCCOPY);
DeleteDC(MemDC); //<
MemDC = CreateCompatibleDC(hdc); //<
SelectObject(MemDC, Histo); //<
SelectObject(MemDC, myPen);
BitBlt(hdc, XPOS + ( SW * 2) + stBfInfo.biWidth +( XGAP*2)+ XGAP, YPOS, XGRAPH, YGRAPH
, MemDC, 0, 0, SRCCOPY);
DeleteDC(MemDC); //<
EndPaint(hWnd, &ps);
return 0;
}
void draw_Bitmap(void )
{
HDC hdc;
int iCntx;
int iCnty;
HDC MemDC;
UINT uiMaxVal;
//평활화
unsigned int uiCnt[256] = { 0, };
hdc = GetDC(hWnd);
Screen = CreateCompatibleBitmap(hdc, stBfInfo.biWidth, stBfInfo.biHeight);//<
Histo = CreateCompatibleBitmap(hdc, XGRAPH+1, YGRAPH); //<
MemDC = CreateCompatibleDC(hdc);
SelectObject(MemDC, Screen);
for (iCnty = 0; iCnty<stBfInfo.biHeight; iCnty++)
{
for (iCntx = 0; iCntx <stBfInfo.biWidth; iCntx++)
{
SetPixel(MemDC, iCntx, stBfInfo.biHeight - iCnty -1
, RGB(*(ucData + (iCnty*stBfInfo.biWidth * 3) + (iCntx * 3) + 2 + iCnty*uiPad)
, *(ucData + (iCnty*stBfInfo.biWidth * 3) + (iCntx * 3) + 1 + iCnty*uiPad)
, *(ucData + (iCnty*stBfInfo.biWidth * 3) + (iCntx * 3) + 0 + iCnty*uiPad)));
//평활화 1단계
++uiCnt[(ucData[iCnty*(stBfInfo.biWidth * 3) + (iCntx * 3) + 2 + (iCnty*uiPad)]+
ucData[iCnty*(stBfInfo.biWidth * 3) + (iCntx * 3) + 1 + (iCnty*uiPad)]+
ucData[iCnty*(stBfInfo.biWidth * 3) + (iCntx * 3) + 0 + (iCnty*uiPad)])/3];
}
}
uiMaxVal = 0;
for (iCntx = 0; iCntx < 256; iCntx++)
{
uiCnt[iCntx] = uiCnt[iCntx] / 3;
if (uiMaxVal < uiCnt[iCntx])
{
uiMaxVal = uiCnt[iCntx];
}
}
for (iCntx = 0; iCntx < 256; iCntx++)
{
uiCnt[iCntx] = (uiCnt[iCntx]* YGRAPH)/uiMaxVal;
}
DeleteDC(MemDC);
free(ucData);
MemDC = CreateCompatibleDC(hdc);
SelectObject(MemDC, Histo);
for (iCntx = 0; iCntx < ( XGRAPH + 1);iCntx++)
{
SetPixel(MemDC, iCntx, YGRAPH-1, RGB(255,0,0));
}
DeleteDC(MemDC);
ReleaseDC(hWnd, MemDC);
return;
}
728x90
'코스웨어 > 15년 스마트컨트롤러' 카테고리의 다른 글
20151124 - 홍준모 - 비트맵 뷰어 마지막, VFW 1일 차 : 원본 사진을 RGB 값 나누어 영상 처리 (5) | 2015.11.24 |
---|---|
20151124 수업 / WinAPI_9-비트맵 히스토그램 그리기, 영상처리 - 남수진 (7) | 2015.11.24 |
20151124 - WinAPI 일지 엄민웅 (PatBlt, CAM 화면 출력) (6) | 2015.11.24 |
20151121 김태현 WinAPI 8일차 비트맵 뷰어2 (5) | 2015.11.24 |
20151123 - WinAPI 일지 엄민웅 (주사방식 NTSC / PAL) (5) | 2015.11.24 |
20151123_안향진_API_8 (4) | 2015.11.24 |
20151123 윤재희 #8. API BMP 뷰어(2) (4) | 2015.11.23 |
20151123 임현수 업무일지 WIN32API #8 비트맵 이미지 뷰어 (5) | 2015.11.23 |