创建一个200x200内存Bitmap
底色为红色,
然后显示在窗体上.
能不能给个例子,或者说说我的程序问题在那里,我的程序现在的问题是什么都没有显示.
UCHAR * pb,pc;
int i;
HBITMAP hbmp;
pb =(UCHAR *) new UCHAR[604][200];
FillMemory(pb,604*200,0);
hbmp  = CreateBitmap(201,200,1,24,pb); HDC dc = ::GetDC(this->m_hWnd);
::ReleaseDC(this->GetSafeHwnd(),dc);
HDC hdc = ::CreateCompatibleDC(dc);
::SelectObject(hdc,hbmp);
BitBlt(dc,0,0,201,200,hdc,0,0,SRCCOPY);
::ReleaseDC(this->GetSafeHwnd(),dc);
DeleteDC(hdc);

解决方案 »

  1.   

    1创建内存BITMAP
    2创建内存DC,选进BITMAP
    3画东西
    4把内存DC  BITBLT 到实际的DC上就OK了
      

  2.   

    UCHAR * pb;
    int nWidth, nHeight;
    nWidth = 200;
    int nByteWidth = (nWidth * 3 / 4) * 4;
    nHeight = 200;
    HBITMAP hbmp;
    pb =(UCHAR *) new UCHAR[nByteWidth * nHeight * sizeof(COLORREF)];
    FillMemory(pb,nByteWidth * nHeight * sizeof(COLORREF), 0);
    hbmp  = CreateBitmap(nWidth, nHeight, 1, 32, pb); HDC dc = ::GetDC(this->m_hWnd);
    // ::ReleaseDC(this->GetSafeHwnd(),dc);
    HDC hdc = ::CreateCompatibleDC(dc);
    HBITMAP hBmpOld = (HBITMAP)::SelectObject(hdc, hbmp);
    BitBlt(dc, 0, 0, nWidth, nHeight, hdc, 0, 0, SRCCOPY);
    ::ReleaseDC(this->GetSafeHwnd(),dc);
    ::SelectObject(hBmpOld);
    ::DeleteObject(hbmp);
    DeleteDC(hdc);
    delete []pb;
      

  3.   

    CreateBitmap(Width,Height,1,24,NULL);是设备不兼容的,就是不能BitBlt出来的,如果你的显示象素是24位的话,就用CreateCompatibleBitmap()
      

  4.   

    This function creates a bitmap with the specified width, height, and bit depth. HBITMAP CreateBitmap(
    int nWidth, 
    int nHeight, 
    UINT cPlanes, 
    UINT cBitsPerPel, 
    CONST VOID *lpvBits
    );
      

  5.   

    我照着上面各位高手的方法试试,发现确实,32bit的位图就是可以显示的,24bit的位图就是没有办法显示的。哎