Skip to content

grap image and font failed? #26

@w136111526

Description

@w136111526

Hello, I use your player to play the video and display text, before the call of the Present window, like to grab a composite image, why not grab it, how can I modify my code:

RECT srcRect = { 0, 0, m_sourceSize.cx, m_sourceSize.cy };
CRect screenPosition = GetScreenPosition();
CRect target(POINT{}, screenPosition.Size());

#ifdef 0
const auto blt = GetVideoProcessBltParams(
target,
m_ProcAmpValues,
m_NFilterValues,
m_DFilterValues);
const auto sample = GetVideoSample(m_sourceSize, target, m_pMainStream);

hr = m_pDXVAVPD->VideoProcessBlt(m_pD3DRT,
    &blt,
    &sample,
    SUB_STREAM_COUNT + 1,
    NULL);
if (FAILED(hr))
{
    TRACE("VideoProcessBlt failed with error 0x%x.\n", hr);
}

#else
m_pD3DD9->Clear(
0,
NULL,
D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0, 0, 0),
1.0f,
0);

hr = m_pD3DD9->StretchRect(
    m_pMainStream,
    &srcRect,
    m_pD3DRT,
    &target,
    D3DTEXF_NONE);
if (FAILED(hr))
{
    TRACE("StretchRect failed with error 0x%x.\n", hr);
}

#endif

std::string subtitle = "这个一个测试文字";
if (!subtitle.empty())
{
	RECT srcRect = { 0, 0, m_sourceSize.cx, m_sourceSize.cy };
	CRect screenPosition = GetScreenPosition();
	CRect target(POINT{}, screenPosition.Size());

	//const auto& convertedSubtitle = CA2T(subtitle.c_str(), CP_UTF8);
	HRESULT hr = m_pD3DD9->BeginScene();
	if (SUCCEEDED(hr))
	{
		DrawSubtitleText(m_pD3DD9, target.Width(), target.Height(),
			CA2W(subtitle.c_str(), GetDocument()->isUnicodeSubtitles() ? CP_UTF8 : CP_ACP));

		m_pD3DD9->EndScene();
	}
}
//grab dest image
{
	IDirect3DSurface9 *pBackBuffer;

	HRESULT hr = m_pD3DD9->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
	D3DSURFACE_DESC desc;
	D3DLOCKED_RECT lr;
	pBackBuffer->GetDesc(&desc);
	pBackBuffer->LockRect(&lr, NULL, D3DLOCK_NOSYSLOCK);
	int width = desc.Width;
	int height = desc.Height;
	int nPitch = lr.Pitch;
	unsigned char* data = (unsigned char*)lr.pBits;
	pBackBuffer->UnlockRect();

	if (SUCCEEDED(hr))
		pBackBuffer->Release();
}

hr = m_pD3DD9->Present(&target, &screenPosition, GetSafeHwnd(), NULL);
if (FAILED(hr))
{
    TRACE("Present failed with error 0x%x.\n", hr);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions