我正在尝试捕获整个桌面屏幕(前缓冲区),并为每个帧添加徽标和标题。
我将徽标(.png或.jpeg文件)加载为IDirect3DTexture9,然后尝试将其添加到IDirect3DSurface9图像框架(截图)。
由于我是DirecX9的新手,所以我不知道如何将徽标(纹理)复制到屏幕截图(表面/缓冲区)。任何帮助将不胜感激。
(如果还有其他方法可以在不涉及纹理的情况下向每个框架添加徽标,请告诉我。)
编辑: 我使用了下面答案中建议的代码。返回的hr结果是错误。
IDirect3DSurface9 *pSurface = NULL;
pDevice->GetFrontBufferData(0, pSurface); //my screenshot
LPDIRECT3DTEXTURE9 tex = NULL; //my logo
//[code to load logo from file here]
IDirect3DSurface9 *pSurf = NULL;
tex->GetSurfaceLevel(0, &pSurf);
hr = pDevice->StretchRect(pSurf, NULL, pSurface, NULL, D3DTEXF_NONE); //HR GIVES AN ERROR
答案 0 :(得分:1)
您可以使用StretchRect。 代码看起来像这样(伪):
ID3DSurface9 *pScreenSurface = ... // your screenshot surface should be created in default pool and the same format as your texture(see bellow), like this:
CreateOffscreenPlainSurface(width, height, D3DFMT_X8B8G8R8, D3DPOOL_DEFAULT, &pScreenSurface, NULL);
// Now get a screenshot by using either GetFrontBufferData, or GetBackBuffer/GetRenderTargetData by supplying pScreenSurface as a parameter (not shown here).
ID3DTexture9 *pTexture = ... // your texture should be loaded in default pool and the same format as your screenshot surface, like this:
D3DXCreateTextureFromFileEx(*ppDevice, L"icon.bmp", 40, 40, D3DX_DEFAULT, 0,
D3DFMT_X8B8G8R8, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL,
NULL, &pTexture);
ID3DSurface9 *pSurf;
pTexture->GetSurfaceLevel(0, &pSurf); // don't forget to Release pSurf after StretchRect
RECT rc = { ... initialize the destination rectangle here };
pDevice->StretchRect(pSurf, NULL, pScreenSurface, &rc);
您需要在目标曲面内指定一个目标矩形,要将纹理复制到该矩形上。