title: Enhanced Video Renderer snapshot image is empty
body: <p>I am trying to use the enhanced video renderer to take a snapshot, image of the current rendered stream. I am able to display a video feed either from a file or capture card. When I run </p>
  
  <pre><code>if (pDisplay)
  {
      BITMAPINFOHEADER lpHeader = { 0 };
      BYTE* lpCurrImage = NULL;
      DWORD bitmapSize = 0;
      LONGLONG timestamp = 0;
      lpHeader.biSize = sizeof(BITMAPINFOHEADER);
  
      if (SUCCEEDED(hr = pDisplay-&gt;GetCurrentImage(&amp;lpHeader, &amp;lpCurrImage, &amp;bitmapSize, &amp;timestamp)))
      {
  </code></pre>
  
  <p>the output image data is 0, see image below:
  <img src="https://i.stack.imgur.com/9CfLV.png" alt="enter image description here"></p>
  
  <p>For some reason, when I use VMR7 or 9, the image works fine and has data (rendering the same video) however EVR does not get an image. The bitmap that outputs is 14kb (which is the header information). </p>
  
  <p>For more info, here is the code that I use to render the EVR:</p>
  
  <pre><code>HRESULT InitializeWindowlessEVR(IGraphBuilder* pGraph, IBaseFilter** ppEVR)
  {
      IBaseFilter* pEvr = NULL;
      CComPtr&lt;IMFGetService&gt; pServices;
      CComPtr&lt;IMFQualityAdvise2&gt; pAdvise;
  
      if (!ppEVR)
          return E_POINTER;
      *ppEVR = NULL;
  
      // Create the VMR and add it to the filter graph.
      HRESULT hr = CoCreateInstance(CLSID_EnhancedVideoRenderer, NULL,
          CLSCTX_INPROC, IID_IBaseFilter, (void**)&amp;pEvr);
      if (SUCCEEDED(hr))
      {
          hr = pGraph-&gt;AddFilter(pEvr, L"Enhanced Video Renderer");
          if (SUCCEEDED(hr))
          {
              // Update the window settings
              CHECK_HR(pEvr-&gt;QueryInterface(IID_IMFGetService, (void**)&amp;pServices));
              CHECK_HR(pServices-&gt;GetService(MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl, (void**)&amp;pVideoDisplay));
              CHECK_HR(pVideoDisplay-&gt;SetVideoWindow(ghApp));
              CHECK_HR(pVideoDisplay-&gt;SetAspectRatioMode(MFVideoARMode_PreservePicture));
          }
  
          pEvr-&gt;AddRef();
          *ppEVR = pEvr;
          pEvr-&gt;Release();
          pEvr = NULL;
      }
  done:
      return hr;
  }
  </code></pre>
  
  <p>Please help me figure out why I am unable to get an image for EVR, I do not want to go back and use VMR9. I can post more code if it helps. Thanks in advance!</p>
  
  <p><strong>Answer:</strong></p>
  
  <pre><code>BOOL CaptureImage(LPCTSTR szFile)
  {
      if (pVideoDisplay)
      {
          BYTE* lpCurrImage = NULL;
          BITMAPINFOHEADER lpHeader = { 0 };
          DWORD bitmapSize = 0;
          LONGLONG timestamp = 0;
          lpHeader.biSize = sizeof(BITMAPINFOHEADER);
  
          if (SUCCEEDED(pVideoDisplay-&gt;GetCurrentImage(&amp;lpHeader, &amp;lpCurrImage, &amp;bitmapSize, &amp;timestamp)))
          {
              // Create a new file to store the bitmap data
              HANDLE hFile = CreateFile(szFile, GENERIC_WRITE, FILE_SHARE_READ, NULL,
                  CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  
              if (hFile == INVALID_HANDLE_VALUE)
                  return FALSE;
  
              DWORD dwWritten;
              BITMAPFILEHEADER fileHeader;
              fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
              fileHeader.bfReserved1 = 0;
              fileHeader.bfReserved2 = 0;
              fileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + lpHeader.biSizeImage;
              fileHeader.bfType = 0x4d42;
  
              // Write the bitmap header and bitmap bits to the file
              WriteFile(hFile, (LPCVOID)&amp;fileHeader, sizeof(BITMAPFILEHEADER), &amp;dwWritten, 0);
              WriteFile(hFile, (LPCVOID)&amp;lpHeader, sizeof(BITMAPINFOHEADER), &amp;dwWritten, 0);
              WriteFile(hFile, (LPCVOID)lpCurrImage, bitmapSize, &amp;dwWritten, 0);
  
              CloseHandle(hFile);
  
              CoTaskMemFree(lpCurrImage);
              return TRUE;
          }
          else
          {
              return FALSE;
          }
      }
      return FALSE;
  }
  </code></pre>