本帖最后由 weiwuyuan 于 2011-10-23 16:12:33 编辑

解决方案 »

  1.   


    很简单,我现在有一个RGB数据,比如:
    int bmp[4*4] =
    {
        0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,
        0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,
        0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,
        0xff00ff, 0xff01ff, 0xff02ff, 0xff03ff,
    };我想把这个RGB数据填充进位图中,怎么填充?
    就是要实现,不从文件加载,从内存加载
      

  2.   

    你是想直接在内存中将位图解码吗?  如果是的话,可以尝试用CXimage这个类库,很强大的
      

  3.   

    http://baike.baidu.com/view/189487.htm
      

  4.   

    其实只要十几行代码就OK了:// 绘制自定义位图像素
    {
    // 获取tga像素
    BYTE* pBmpData = NULL;
    int bmpWidth = 0;
    int bmpHeight = 0; GetBmpFromTga("test.tga", &pBmpData, &bmpWidth, &bmpHeight, NULL);
    UINT* pBmp32 = (UINT*)pBmpData; const int BMP_WIDTH = bmpWidth;
    const int BMP_HEIGHT = bmpHeight; HBITMAP hCustomBmp = CreateCompatibleBitmap(hdc, BMP_WIDTH, BMP_HEIGHT); UINT* pData = new UINT[BMP_WIDTH*BMP_HEIGHT];   
    BITMAPINFO bmpInfo;   
    bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);   
    bmpInfo.bmiHeader.biWidth = BMP_WIDTH;   
    bmpInfo.bmiHeader.biHeight = BMP_HEIGHT;   
    bmpInfo.bmiHeader.biPlanes = 1;   
    bmpInfo.bmiHeader.biCompression = BI_RGB;   
    bmpInfo.bmiHeader.biBitCount = 32;    GetDIBits(hdc, hCustomBmp, 0, BMP_HEIGHT, pData, &bmpInfo, DIB_RGB_COLORS);    for (int i=0; i<BMP_WIDTH*BMP_HEIGHT; i++)   
    {   
    pData[i] = (*pBmp32) & 0x00ffffff;
    pBmp32++;
    } SetDIBits(hdc, hCustomBmp, 0, BMP_HEIGHT, pData,&bmpInfo, DIB_RGB_COLORS); HDC hh = CreateCompatibleDC(NULL);
    SelectObject(hh, hCustomBmp);
    BitBlt(hdc, 0, 0, BMP_WIDTH, BMP_HEIGHT, hh, 0, 0, SRCCOPY);
    }