CreateBitmap,SetBitmapBits用法,怎么显示不出来呢
CClientDC pDC(this);
CDC DSDC,DC;
CBitmap bitmap1;
CBitmap* bitmap;
bitmap = memDCShibie.GetCurrentBitmap();
unsigned int * buf = (unsigned int *) new BYTE[imageWidth*imageHeight*4];
long a = bitmap->GetBitmapBits (imageWidth *imageHeight*4,buf);//a=20155392,û´í£¬Äõõ½Êý¾Ý
//pDC.StretchBlt (rectCuantuCtrl.left,rectCuantuCtrl.top,rectCuantuCtrl.Width(),rectCuantuCtrl.Height(),
// &memDCShibie,0,0,2592,1944,SRCCOPY);//ÏÔʾµÃ³öÀ´£¬Ö¤Ã÷memDCShibieÀïÃæÓÐͼƬÔÚ
bitmap1.CreateBitmap(2592,1944,1,4,buf);
//long b = bitmap1.SetBitmapBits (imageWidth *imageHeight*4,buf);
DC.CreateCompatibleDC (&pDC);
DC.SelectObject (&bitmap1);
pDC.StretchBlt (rectCuantuCtrl.left,rectCuantuCtrl.top,rectCuantuCtrl.Width(),rectCuantuCtrl.Height(),
&DC,0,0,2592,1944,SRCCOPY);
怎么显示不出来呢,a的值没错啊,为什么,利用createbitmap把32位位图变成1位位图,这样不对吗
------解决方案--------------------------------------------------------
不好意思,GDI只能处理当前屏幕的颜色模式,你的当前屏幕的颜色模式应该是32位色,所以你用GDI的函数只能处理32位色的CBitmap。如果你用GDI加载一张16位色的图片,你会发现它根本显示不出来。
如果你想这样用,请使用而GDI+
------解决方案--------------------------------------------------------
Sample Code:
CClientDC pDC(this);
CDC DSDC,DC;
CBitmap bitmap1;
CBitmap* bitmap;
bitmap = memDCShibie.GetCurrentBitmap();
unsigned int * buf = (unsigned int *) new BYTE[imageWidth*imageHeight*4];
long a = bitmap->GetBitmapBits (imageWidth *imageHeight*4,buf);//a=20155392,û´í£¬Äõõ½Êý¾Ý
//pDC.StretchBlt (rectCuantuCtrl.left,rectCuantuCtrl.top,rectCuantuCtrl.Width(),rectCuantuCtrl.Height(),
// &memDCShibie,0,0,2592,1944,SRCCOPY);//ÏÔʾµÃ³öÀ´£¬Ö¤Ã÷memDCShibieÀïÃæÓÐͼƬÔÚ
bitmap1.CreateBitmap(2592,1944,1,4,buf);
//long b = bitmap1.SetBitmapBits (imageWidth *imageHeight*4,buf);
DC.CreateCompatibleDC (&pDC);
DC.SelectObject (&bitmap1);
pDC.StretchBlt (rectCuantuCtrl.left,rectCuantuCtrl.top,rectCuantuCtrl.Width(),rectCuantuCtrl.Height(),
&DC,0,0,2592,1944,SRCCOPY);
怎么显示不出来呢,a的值没错啊,为什么,利用createbitmap把32位位图变成1位位图,这样不对吗
------解决方案--------------------------------------------------------
不好意思,GDI只能处理当前屏幕的颜色模式,你的当前屏幕的颜色模式应该是32位色,所以你用GDI的函数只能处理32位色的CBitmap。如果你用GDI加载一张16位色的图片,你会发现它根本显示不出来。
如果你想这样用,请使用而GDI+
------解决方案--------------------------------------------------------
Sample Code:
-
C/C++ code
CBitmap bitmap; unsigned int *pImageRawDate = (unsigned int *) new BYTE[64 * 64 * 4]; memset(pImageRawDate, 0xFF, 64 * 64 * 4); bitmap.CreateBitmap(64, 64, 1, 4, pImageRawDate); HDC hMainDC = ::GetDC(m_hWnd); HDC hMemoryDC = ::CreateCompatibleDC(hMainDC); HDC hBitmapDC = ::CreateCompatibleDC(hMainDC); HBITMAP hMainSurface = ::CreateCompatibleBitmap(hMainDC, 800, 600); ::SelectObject(hMemoryDC, hMainSurface); ::BitBlt(hMainDC, 0, 0, 800, 600, hMemoryDC, 0, 0, SRCCOPY); ::SelectObject(hBitmapDC, &bitmap); ::BitBlt(hMemoryDC, 0, 0, 64, 64, hBitmapDC, 0, 0, SRCCOPY);