랭귀지/API

실행 도중 이미지가 출력이 안될 때! CreateDIBSection 함수

Angler.lee 2008. 11. 17. 12:36
보통 이미지를 불러올 때 CreateCompatibleBitmap 함수를 사용한다.  

CreateCompatibleBitmap 함수의 단점은 DC 의 크기가 16MB 로 제한되어 있다는 것이다.

이 문제점의 해결책은 CreateDIBSection 함수이다.

HBITMAP MakeDIBSection(HDC hdc, int width, int height)   
{   
    BITMAPINFO  bmi;   
    LPVOID      pBits;   
    HBITMAP     hBitmap;   
  
    memset(&bmi.bmiHeader, 0, sizeof(BITMAPINFOHEADER));   
  
    bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);   
    bmi.bmiHeader.biBitCount    = 24;          // 칼라수  : 1, 4, 8, 16, 24, 31   
    bmi.bmiHeader.biWidth       = width;       //비트맵 너비   
    bmi.bmiHeader.biHeight      = height;      //비트매 높이   
    bmi.bmiHeader.biPlanes      = 1;   
    hBitmap = CreateDIBSection( hdc, &bmi, DIB_RGB_COLORS, (void **)&pBits, NULL, 0);   
  
    return hBitmap;   
}