DirectShow 視頻上畫線和輸出文字

來源:互聯網
上載者:User

 

為了方便,就直接在視頻上顯示了,而沒有動態輸出文字和用滑鼠移動畫線,不過是一樣的原理,只是動態就要捕獲滑鼠狀態的訊息

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;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.