Click here to Skip to main content
15,867,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
I am trying to draw a line over the live video streaming in direct show application. Am successfully drawing a line but if I continuously want to create a line by calling the below function, i got an error E_OUTOFMEMORY from the SetAlphaBitmap(). Am calling drawlineOverlay() function one after the other and 8 of the calling is ok, but the ninth and subsequent ones do not. SetAlphaBitmap returns S_OK for the first 8 callings and then the 9th returns 8007000E.

Why is this error occuring?


Thanks!!

What I have tried:

void drawlineOverlay(HWND m_hwndApp)
{
	int cx, cy;
    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;
    }				
	//To draw line
	drawLine1(xx1, yy1, xx2, yy2,hdcBmp,2);

	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 = 1.0f;
	bmpInfo.rDest.bottom = 1.0f;

	// 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());
			}
			pBmp->Release();
			//SAFE_RELEASE(pBmp);

		}
	}
	// Clean up.
	ReleaseDC(m_hwndApp, hdc);
	DeleteBitmap(hbm);
	DeleteObject(SelectObject(hdcBmp, hbmOld));
	DeleteDC(hdcBmp);
}
Posted
Updated 16-Jan-17 3:42am
v2

1 solution

Create and populate the bitmap and the other stuff once at program start. These operations are "expensive" so do them as less as possible.

C++
//Gobal bitmap
BITMAP bm = {0};// init with zeros

void drawlineOverlay(HWND m_hwndApp)
{
  //run code once
  if( bm.bmWidth == 0 ) {
    // set up bitmap
  }
Destroy the bitmpa at program end or when needed.
 
Share this answer
 
Comments
EsakkiRaja 16-Jan-17 8:16am    
Thanks for your response. But i tried with BITMAP bm as global but still i have the same problem..can we continuously call this function(drawlineOverlay)?
EsakkiRaja 16-Jan-17 8:17am    
Am new to directshow and bitmap rendering. How to destroy the bitmap ?
EsakkiRaja 16-Jan-17 8:51am    
From my friend's reference, he also done this with text blending with the video, but he also met with this problem..for continuous calling of overlay function, the overlay text remain hanged(doesn't get update) but the video was continuously streaming. Afterwards he left that project for unknowing issues.
KarstenK 23-Jan-17 5:55am    
If you Google you find that you need to use DeleteObject. For redrawing you must call InvalideRect with the correct values.

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