為了方便,就直接在視頻上顯示了,而沒有動態輸出文字和用滑鼠移動畫線,不過是一樣的原理,只是動態就要捕獲滑鼠狀態的訊息
LONG cx, cy;HRESULT hr;hr = pWC->GetNativeVideoSize(&cx, &cy, NULL, NULL);if (FAILED(hr)){Msg(TEXT("GetNativeVideoSize FAILED! hr=0x%x\r\n"), hr);return hr;}HDC hdc = GetDC(hwndApp);HDC hdcBmp = CreateCompatibleDC(hdc);g_hFont=CreateFont(30, 10,0,0, 10, FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,_T("宋體"));HFONT hOldFont = (HFONT) SelectObject(hdcBmp, g_hFont);HPEN hPen=CreatePen(PS_SOLID,1,RGB(255,0,0));HPEN hOldPen = (HPEN) SelectObject(hdcBmp, hPen);int nLength, nTextBmpWidth, nTextBmpHeight;SIZE sz={0};nLength = (int) _tcslen(szNewText);GetTextExtentPoint32(hdcBmp, szNewText, nLength, &sz);nTextBmpHeight = sz.cy;nTextBmpWidth = 400/*sz.cx*/;HBITMAP hbm = CreateCompatibleBitmap(hdc, nTextBmpWidth, nTextBmpHeight);ReleaseDC(hwndApp, hdc);BITMAP bm;HBITMAP hbmOld;GetObject(hbm, sizeof(bm), &bm);hbmOld = (HBITMAP)SelectObject(hdcBmp, hbm);RECT rcText;SetRect(&rcText, 0, 0, nTextBmpWidth, nTextBmpHeight);SetBkMode(hdcBmp,TRANSPARENT); //設定透明背景SetTextColor(hdcBmp, g_rgbColors); // 文字顏色HBRUSH hBrush=((HBRUSH)GetStockObject(NULL_BRUSH)); SelectObject(hdcBmp, hBrush);// 在位元影像上畫圖//輸出文字//TextOut(hdcBmp, 0, 0, szNewText, nLength);DrawText(hdcBmp,szNewText,sizeof(szNewText),&rcText,DT_RIGHT);//畫線MoveToEx(hdcBmp,10,10,NULL);LineTo(hdcBmp,200,10);//Ellipse(hdcBmp,0,0,100,nTextBmpHeight);// Configure the VMR's bitmap structureVMRALPHABITMAP bmpInfo;ZeroMemory(&bmpInfo, sizeof(bmpInfo) );bmpInfo.dwFlags = VMRBITMAP_HDC;bmpInfo.hdc = hdcBmp; g_nImageWidth = bm.bmWidth;g_fBitmapCompWidth = (float)g_nImageWidth / (float)cx;bmpInfo.rDest.left = 0.0f + X_EDGE_BUFFER;bmpInfo.rDest.right = 1.0f - X_EDGE_BUFFER;bmpInfo.rDest.top = (float)(cy - bm.bmHeight) / (float)cy - Y_EDGE_BUFFER;bmpInfo.rDest.bottom = 1.0f - Y_EDGE_BUFFER;bmpInfo.rSrc = rcText;bmpInfo.fAlpha = TRANSPARENCY_VALUE;SetColorRef(bmpInfo);hr = pBMP->SetAlphaBitmap(&bmpInfo);if (FAILED(hr))Msg(TEXT("SetAlphaBitmap FAILED! hr=0x%x\r\n\r\n%s\0"), hr,STR_VMR_DISPLAY_WARNING);// Select the initial objects back into our device contextDeleteObject(SelectObject(hdcBmp, hbmOld));DeleteObject(SelectObject(hdcBmp, hOldPen));SelectObject(hdc, hOldFont);DeleteObject(hbm);DeleteDC(hdcBmp);return hr;