原先使用cximage库,load一个bmp文件,然后得到一个HBITMAP(m_bitmap ).以下是原来的代码。
CxImage image(strFilePath, CXIMAGE_FORMAT_BMP);
if(image.IsValid())
{
if(m_bitmap)
{
DeleteObject(m_bitmap);
m_bitmap = NULL;
} m_bitmap = image.MakeBitmap();
}
现在的要求是,直接得到一块bits的数据,知道长,宽,24位的数据,如何从这块数据转换成HBITMAP(m_bitmap )?试验好久了,m_bitmap有值,但是图像不显示(图像显示沿用以前的,怀疑自己的转换有问题),请教大家该怎么实现?能给出具体的代码吗?谢谢大家!

解决方案 »

  1.   

    HBITMAP CreateBitmap(
      int nWidth,         // bitmap width, in pixels
      int nHeight,        // bitmap height, in pixels
      UINT cPlanes,       // number of color planes
      UINT cBitsPerPel,   // number of bits to identify color
      CONST VOID *lpvBits // color data array
    );
      

  2.   

    lpvBits 
    [in] Pointer to an array of color data used to set the colors in a rectangle of pixels. Each scan line in the rectangle must be word aligned (scan lines that are not word aligned must be padded with zeros). If this parameter is NULL, the contents of the new bitmap is undefined.
      

  3.   

    我用这个函数试了也不行,CBitmap::CreateBitmapIndirect实际上也是显示CBitmap HBITMAP都是正常的,可就是显示不出来。
      

  4.   

    用GDI的SetDIbits()吧, 将一个DIB(bits)转换为DDB(HBITMAP), 你要提供一个BITMAPINFO结构来告诉GDI, DIB(bits)的结构, GDI才能完成转换.函数用法: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_0qk3.asp例子:
    http://support.microsoft.com/kb/81498
      

  5.   

    已经解决了,使用CreateDIBitmap即可