D3D等比缩放渲染

D3D进行视频等比缩放渲染,主要使用StretchRect函数指定dst rect(区域放大可通过指定src rect)实现,关键代码如下

	int srcW = 352, srcH = 288, dstW = 800, dstH = 600;
	int dw = 0, dh = 0, dx = 0, dy = 0;
	float x = 0, y = 0;
	x = ( float )dstW / ( float )srcW;             // window width / video width
	y = ( float )dstH / ( float )srcH;             // window height / video height
	if ( x > y )
	{
	  dw = srcW * y;
	  dh = srcH * y;                             // stretch to window height
	}
	else
	{
	  dw = srcW * x;
	  dh = srcH * x;                             // stretch to window width
	}
	dx = ( dstW - dw ) / 2;                        // x offset
	dy = ( dstH - dh ) / 2;                        // y offset
	RECT rt = {0};                                 // dest value / window and video stretch rate
	rt.left = dx / x;
	rt.top = dy / y;
	rt.right = rt.left + dw / x;
	rt.bottom = rt.top + dh / y;
	pDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(88,88,88), 1.0f, 0 );
	pDevice->StretchRect( src, NULL, dst, &rt, D3DTEXF_LINEAR );
	pDevice->BeginScene();
	//....
	pDevice->EndScene();
	pDevice->Present( NULL, NULL, NULL, NULL );

你可能感兴趣的:(流媒体)