WINCE에서 HBITMAP에서 비트맵 RGB 색상 데이터 가져오기
, , , :
class CBitmapBits
{
public:
CBitmapBits()
: m_pBitsBuf(NULL)
, m_dwWidth(0)
, m_dwHeight(0)
{
}
~CBitmapBits()
{
Destroy();
}
//
void Destroy()
{
if (m_pBitsBuf != NULL)
{
delete[] m_pBitsBuf;
m_pBitsBuf = NULL;
}
m_dwWidth = 0;
m_dwHeight = 0;
}
public:
BYTE *m_pBitsBuf; // RGB , , 4 , : * *3
DWORD m_dwWidth; //
DWORD m_dwHeight; //
};
// HBITMAP DC
BOOL
DrawHBitmapToDC(
IN HBITMAP hBitmap, //
IN HDC hDC // DC
)
{
//
if (hBitmap==NULL || hDC==NULL)
{
return FALSE;
}
// ,
BITMAP bmpObj = {0};
if ( ::GetObject(hBitmap, sizeof(bmpObj), &bmpObj) == 0
|| bmpObj.bmWidth <= 0
|| bmpObj.bmHeight <= 0
)
{
return FALSE;
}
// DC
HDC hMemDC = ::CreateCompatibleDC(hDC);
if (hMemDC == NULL)
{
return FALSE;
}
// HBITMAP DC
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hMemDC, hBitmap);
// DC DC
::BitBlt(hDC, 0, 0, bmpObj.bmWidth, bmpObj.bmHeight, hMemDC, 0, 0, SRCCOPY);
// DC
::SelectObject(hMemDC, hOldBitmap);
::DeleteDC(hMemDC);
//
return TRUE;
}
// HBITMAP
BOOL
GetHBitmapBits(
IN HBITMAP hBitmap, //
OUT CBitmapBits &bitmapBits //
)
{
//
bitmapBits.Destroy();
//
if (hBitmap == NULL)
{
return FALSE;
}
// ,
BITMAP bmpObj = {0};
if ( ::GetObject(hBitmap, sizeof(bmpObj), &bmpObj) == 0
|| bmpObj.bmWidth <= 0
|| bmpObj.bmHeight <= 0
)
{
return FALSE;
}
// DIB DC
HDC hDIBDC = ::CreateCompatibleDC(NULL);
if (hDIBDC == NULL)
{
return FALSE;
}
// DIB
BITMAPINFO hdr;
ZeroMemory(&hdr , sizeof(BITMAPINFO));
hdr.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
hdr.bmiHeader.biWidth = bmpObj.bmWidth;
hdr.bmiHeader.biHeight = -bmpObj.bmHeight; //
hdr.bmiHeader.biPlanes = 1;
hdr.bmiHeader.biBitCount = 32;
BYTE * pbtPixels = NULL;
HBITMAP hDIBitmap = ::CreateDIBSection(hDIBDC, (BITMAPINFO *)&hdr, DIB_RGB_COLORS, (void **)&pbtPixels, NULL, 0);
if (hDIBitmap == NULL)
{
::DeleteDC(hDIBDC);
return FALSE;
}
// DIB DIB DC
HBITMAP hOldDIBBmp = (HBITMAP)::SelectObject(hDIBDC, hDIBitmap);
// HBITMAP DIB DC
if (DrawHBitmapToDC(hBitmap, hDIBDC) == FALSE)
{
::SelectObject(hDIBDC, hOldDIBBmp);
::DeleteDC(hDIBDC);
::DeleteObject(hDIBitmap);
return FALSE;
}
// pbtPixels bitmapBits
//
bitmapBits.m_pBitsBuf = new BYTE[bmpObj.bmWidth*bmpObj.bmHeight*3];
if (bitmapBits.m_pBitsBuf == NULL)
{
::SelectObject(hDIBDC, hOldDIBBmp);
::DeleteDC(hDIBDC);
::DeleteObject(hDIBitmap);
return FALSE;
}
//
bitmapBits.m_dwWidth = bmpObj.bmWidth;
bitmapBits.m_dwHeight = bmpObj.bmHeight;
// RGB
long lSrcRowStartPos = 0;
long lSrcPos = 0;
long lDstRowStartPos = 0;
long lDstPos = 0;
for (long lRowIndex=0; lRowIndex<bmpObj.bmHeight; lRowIndex++)
{
//
lSrcRowStartPos = lRowIndex * bmpObj.bmWidth * 4;
lDstRowStartPos = lRowIndex * bmpObj.bmWidth * 3;
//
for (long lColumnIndex=0; lColumnIndex<bmpObj.bmWidth; lColumnIndex++)
{
// ,
lSrcPos = lSrcRowStartPos + lColumnIndex*4;
lDstPos = lDstRowStartPos + lColumnIndex*3;
// BGRA 4 , RGB
bitmapBits.m_pBitsBuf[lDstPos] = pbtPixels[lSrcPos+2];
bitmapBits.m_pBitsBuf[lDstPos+1] = pbtPixels[lSrcPos+1];
bitmapBits.m_pBitsBuf[lDstPos+2] = pbtPixels[lSrcPos];
}
}
// DIB DC
::SelectObject(hDIBDC, hOldDIBBmp);
::DeleteDC(hDIBDC);
::DeleteObject(hDIBitmap);
//
return TRUE;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[Core Javascript] JS 분석 from scratch: 데이터, 변수, 메모리 관련 기본지식이런 언어의 기반이 되는 지식을 알아야 나중에 더 능숙하게 다룰 수 있겠다 싶었습니다. 그렇다면 기본형과 참조형 데이터를 구분하는 기준은 무엇일까요? 이것을 이해하기 위해 알아야할 배경지식들이 있습니다. 변수와 식별...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.