使用IBasicVideo::GetCurrentImage得到存有完整DIB图像的buffer请问怎么转换可以成为HBITMAP呢?使用SetBitmap()显示在界面上面.HBITMAP SetBitmap(HBITMAP hBitmap);

解决方案 »

  1.   

    参考下列代码://转换数据到缓冲区(m_pBuf)
    //所有数据转化为16位565颜色格式
    PBYTE   pD     = pServer->m_pBuf;
    PBYTE   pByte  = (PBYTE)Desc.lpSurface;
    int     width  = rcUpdate.Width();
    int     height = rcUpdate.Height(); switch( pServer->m_nRGBBitCount ) 
    {
    case 32:
    {
    DWORD   *pS;
    short   *pDest;
    for(i=0; i<height; i++)
    {
     pS    =(DWORD *)pByte; 
     pDest =(short *)(pD+width*2*i);
     for( j=0; j<width; j++)
    *pDest++ = (short)(((*pS>>3)&0x1f) |
    ((*pS >>5)&0xfc0) | ((*pS++ >> 8)&0xf800));
    pByte += pServer->m_nlPitch;
    }
    }break; case 24:
    {
    BYTE  *pS;
    short *pDest;
    for( i=0; i<height; i++)
    {
     pS   =pByte; 
     pDest=(short *)(pD+width*2*i); 
     for(j=0;j<width;j++)
     {
     *pDest++ = (*(pS+2)>>3)<<11 | (*(pS+1)>>2)<<5 | (*pS>>3);
     pS += 3; 
     }
     pByte += pServer->m_nlPitch;
    }
    }break; case 16:
    {
    if(pServer->m_bIsRGB565) 
    {
    for(i=0; i<height; i++)
    {
    Copy_Memory(pD+width*2*i, pByte, width*2);
         pByte += pServer->m_nlPitch;
    }
    }else 
    {
    short *pS,*pDest;
    for( i=0; i<height; i++)
    {
     pS    =(short *)pByte;
     pDest =(short *)(pD+width*2*i);
     for( j=0; j<width; j++)
    *pDest++ = ((*pS)<<1) & 0xffc0 | ((*pS++) & 0x1f);
     pByte += pServer->m_nlPitch;
    }
    }
    }break;
    } //保存数据到文件
    DWORD targetsize = width*height*2 + 2048;
    HRESULT hResult;
    hResult=TRUE;
    ::memcpy(pServer->m_pSendBuf,pServer->m_pBuf,width*height*2); if( SUCCEEDED(hResult) )
    {
    try

    //写入类型信息
    pServer->m_RecordFile.Write(&BITMAP_DATA, sizeof(BYTE));

    //写入位图数据
    dblock.xCursor   = (short)ptCursor.x;
    dblock.yCursor   = (short)ptCursor.y;
    dblock.left      = (short)rcUpdate.left;
    dblock.top       = (short)rcUpdate.top;
    dblock.width     = (short)width;
    dblock.height    = (short)height;
    dblock.nsizeData = targetsize;
    dblock.nTime     = GetTickCount() - nStartTime; pServer->m_RecordFile.Write(&dblock, sizeof(DATABLOCK));
    pServer->m_RecordFile.Write(pServer->m_pSendBuf,targetsize); }catch(...)
    {
    MessageBox(NULL, "磁盘写入错误!", "提示",MB_ICONERROR); 
    exit(0);
    } //TODO
    //break; //Only One picture
    }