|
您好,你可以参考如下代码:- /**
- * 视频数据扩展回调(增加时间戳)
- * @param dwUserid 用户ID号
- * @param lpBuf 视频数据缓冲区
- * @param dwLen 缓冲区大小
- * @param bmiHeader 视频缓冲区的头信息,包含了视频的大小、颜色位数等信息
- * @param dwTimeStamp 时间戳
- */
- void CALLBACK OnAnyChatVideoDataExCallBack(DWORD dwUserid, LPVOID lpBuf, DWORD dwLen, BITMAPINFOHEADER bmiHeader, DWORD dwTimeStamp, LPVOID lpUserValue)
- {
- TRACE("VideoDataExCallBack: userid:%d, timestamp:%d\r\n", (int)dwUserid, dwTimeStamp);
- CAnyChatInputVideoDlg* lpDlg = (CAnyChatInputVideoDlg*)lpUserValue;
- CRect dispRect;
- HWND hWnd;
- if(lpDlg->m_dwRemoteUserId == dwUserid && dwUserid != -1) // 远程用户
- {
- hWnd = lpDlg->GetDlgItem(IDC_STATIC_REMOTEVIDEO)->GetSafeHwnd();
- lpDlg->GetDlgItem(IDC_STATIC_REMOTEVIDEO)->GetClientRect(dispRect);
- }
- else // 本地用户
- {
- hWnd = lpDlg->GetDlgItem(IDC_STATIC_LOCALVIDEO)->GetSafeHwnd();
- lpDlg->GetDlgItem(IDC_STATIC_LOCALVIDEO)->GetClientRect(dispRect);
- }
-
- //构建Bitmap
- BITMAPINFOHEADER *lpbmi = (BITMAPINFOHEADER*)malloc(sizeof(BITMAPINFOHEADER)+dwLen);
- ZeroMemory(lpbmi,sizeof(BITMAPINFOHEADER)+dwLen);
- memcpy((LPBYTE)lpbmi,&bmiHeader,sizeof(BITMAPINFOHEADER));
- memcpy(((LPBYTE)lpbmi+sizeof(BITMAPINFOHEADER)),lpBuf,dwLen);
-
- HDC hdc = ::GetDC(hWnd);
- HDC dcMem = ::CreateCompatibleDC(hdc);
- HBITMAP hBitmap = CreateDIBitmap(hdc,lpbmi,CBM_INIT,(LPBYTE)lpbmi+sizeof(BITMAPINFOHEADER),(LPBITMAPINFO)lpbmi,DIB_RGB_COLORS);
- //绘图
- HBITMAP holdbm = (HBITMAP)SelectObject(dcMem,hBitmap);
- ::SetStretchBltMode(hdc,COLORONCOLOR);
- ::StretchBlt(hdc,dispRect.left,dispRect.top,dispRect.Width(),dispRect.Height(),dcMem,0,0,bmiHeader.biWidth,bmiHeader.biHeight,SRCCOPY);
-
- SelectObject(dcMem,holdbm);
- ::DeleteDC(dcMem);
- ::DeleteObject(hBitmap);
- ::ReleaseDC(hWnd,hdc);
- free(lpbmi);
- lpbmi = NULL;
- }
复制代码 |
|