CBitmap CrateBitmap

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:
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);
				
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值