Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i want to draw a line over the live video streaming in the windows application made with directshow in c++.

What I have tried:

So far i tried to draw a rectangle over the streaming using FillRect function and also the output was came . but i need to draw a line from any point to any point.
Posted
Updated 9-Jan-17 2:23am
Comments
Afzaal Ahmad Zeeshan 6-Jan-17 9:16am    
You can try having a rectangle of height 1 pixel. :-)
EsakkiRaja 9-Jan-17 1:32am    
i tried it but for the straight line on both x axis and y axis are well and good but when i want to draw a line with slope means it is not possible to draw it..
Afzaal Ahmad Zeeshan 9-Jan-17 5:16am    
Hopefully, there will be a rotate function available too. :D
Richard MacCutchan 6-Jan-17 10:01am    
Then don't use FillRect, use one of thew line drawing methods.
EsakkiRaja 9-Jan-17 1:33am    
is there any line drawing methods to draw over the video..if yes then let me know?

The best way is to create a top-most window with transparent background and than draw the line in it.
 
Share this answer
 
Comments
EsakkiRaja 9-Jan-17 1:30am    
Thanks..I need to draw a line when i click the mouse button, so from your solution is it possible to create a transparent window on mouse click? if yes then how to render it to the VMR9 video renderer?
drawLine1(int xx1, int yy1, int xx2, int yy2,HDC hdcBmp) 
{
	RECT clntRc;
	int temp,s1,s2,swap;
	x = xx1;
	y = yy1;
	dx = abs(xx2 - xx1);
	dy = abs(yy2 - yy1);
	s1 = sign(xx2 - xx1); 
	s2 = sign(yy2 - yy1);
	swap = 0;
	if (dy > dx)
	{ 
		temp = dx; 
		dx = dy;
		dy = temp;
		swap = 1;
	}
	p = 2*dy - dx;
	for (int i = 0; i < dx; i++)
	{
		clntRc.left =x;
		clntRc.top = y;
		clntRc.right = x;
		clntRc.bottom =y;	
		FrameRect(hdcBmp,&clntRc,CreateSolidBrush(RGB(255,0,0)));

		while (p >= 0)
		{ 
			p = p - 2*dx; 
			if (swap)
				x += s1; 
			else
				y += s2;
		}
			p = p + 2*dy; 
			if (swap) 
				y += s2; 
			else 
				x += s1;
	}
}


drawlineOverlay()
{
	int cx, cy,count;
    HRESULT hr;
	HBITMAP hbm;
	RECT rcClient;
	

	GetResolution(&cx,&cy);

	GetClientRect(m_hwndApp,&rcClient);

    HDC hdc = GetDC(m_hwndApp);

    if (hdc == NULL)
    {
        return E_FAIL;
    }
    
    HDC hdcBmp = CreateCompatibleDC(hdc);    
    if (hdcBmp == NULL)
    {
        return E_FAIL;
    }
    
	hbm = CreateCompatibleBitmap(hdc,cx,cy);

	BITMAP bm;
	if (0 == GetObject(hbm, sizeof(bm), &bm))
	{
		DeleteDC(hdcBmp);
		return E_FAIL;
	}			

    HBITMAP hbmOld = (HBITMAP)SelectObject(hdcBmp, hbm);
    if (hbmOld == 0)
    {
        DeleteDC(hdcBmp);
        return E_FAIL;
    }				
	
	if(g_bTOFToFindAreaSelect)
	{
		count = g_SelectedCoordinatesValue;
		for(int i = 1;i <= count;i++)
		{
			if(i == count)
				drawLine1(xxpos[i], yypos[i], xxpos[1], yypos[1],hdcBmp);
			else
				drawLine1(xxpos[i], yypos[i], xxpos[i+1], yypos[i+1],hdcBmp);
		}
	}

	if(g_bTOFToFindLengthSelect)
	{
		drawLine1(xx1, yy1, xx2, yy2,hdcBmp);	
	}
  

	VMR9AlphaBitmap bmpInfo;
	ZeroMemory(&bmpInfo, sizeof(bmpInfo) );

	bmpInfo.dwFlags = VMRBITMAP_HDC | VMRBITMAP_SRCCOLORKEY;

	bmpInfo.hdc = hdcBmp;
	        
	SetRect(&bmpInfo.rSrc, 0, 0, bm.bmWidth, bm.bmHeight);   
	bmpInfo.rDest.left = 0.f;
	bmpInfo.rDest.top = 0.f;
	//bmpInfo.rDest.right = bmpInfo.rDest.left + ((float)bm.bmWidth / (float)cx); 
	//bmpInfo.rDest.bottom = bmpInfo.rDest.top + ((float)bm.bmHeight / (float)cy);
	bmpInfo.rDest.right = 1.f;
	bmpInfo.rDest.bottom = 1.f;

	// Set the transparency value (1.0 is opaque, 0.0 is transparent).
	bmpInfo.fAlpha = 0.5f;	
	bmpInfo.clrSrcKey = RGB(0,0,0);

	if(m_pVideoRender != NULL)
	{
		IVMRMixerBitmap9* pBmp;	
		hr = m_pVideoRender->QueryInterface(IID_IVMRMixerBitmap9, (LPVOID *)&pBmp);
		if (SUCCEEDED(hr)) 
		{
			hr = pBmp->SetAlphaBitmap(&bmpInfo);
			if(FAILED(hr))
			{
				PrintMessage(L"pBmp->SetAlphaBitmap hr = 0x%x  GetLastError() = %d\r\n",hr,GetLastError());
			}
			hr = pBmp->Release();
			if(FAILED(hr))
			{
				PrintMessage(L"pBmp->Release hr = 0x%x  GetLastError() = %d\r\n",hr,GetLastError());
			}
		}
	}
	

	// Clean up.
	ReleaseDC(m_hwndApp, hdc);
	DeleteBitmap(hbm);
	DeleteObject(SelectObject(hdcBmp, hbmOld));
	DeleteDC(hdcBmp);
    return hr;
}



i got the solution..thanks every one!!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900