使用DirectX9截取屏幕截图
Hello Everyone ..
这是DirectX编程的新手。最近我安装了DirectX9&设置VS 2008.我试图截取桌面(客户端区域,即不是整个桌面,只在桌面上指定区域)的屏幕截图。我已经用Google搜索了这个&找到了一堆代码。
Hello Everyone..
Am new to this DirectX programming. Recently i have installed DirectX9 & setup with VS 2008. Am trying to take screenshot of Desktop ( client area i.e., not entire desktop, only specified region on desktop ). I''ve googled on this & found a peice of code.
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
IDirect3DDevice9* g_pd3dDevice;
int ScreenWidth = 100;
int ScreenHeight = 100;
void CaptureScreen()
{
IDirect3DSurface9* pSurface;
g_pd3dDevice->CreateOffscreenPlainSurface(ScreenWidth, ScreenHeight,
D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL);
g_pd3dDevice->GetFrontBufferData(0, pSurface);
D3DXSaveSurfaceToFile("E:\\Desktop.bmp",D3DXIFF_BMP,pSurface,NULL,NULL);
pSurface->Release();
}
void CDirectXProject::Screenshot()
{
CaptureScreen();
}
在链接器属性中 - >输入我已经参考了d3d9.lib d3dx9.lib。在项目文件夹中,我保留了d3d9.dll,d3d9.lib& d3dx9.lib文件。
但是当我运行程序时,它会在CreateOffscreenPlainSurface函数崩溃,说明访问冲突。我没有弄到这个问题。而且我还指定了图像宽度和宽度。高度。但是我如何指定客户区域,即x& y cordinate。
请建议我这个。
谢谢大家..
And in Linker Properties -> Input I''ve refrenced d3d9.lib d3dx9.lib. In project folder, I''ve kept d3d9.dll, d3d9.lib & d3dx9.lib files.
But when i run the program, it crashes at CreateOffscreenPlainSurface function stating that Access violation. Am not getting what am doing wrong with this. And also i''ve specified the Image width & HEight. But how do i specify the client region i.e., x & y cordinate.
Please suggest me on this.
Thank you all..
你好。
1.使用系统内存池而不是临时(D3DPOOL_SYSTEMMEM
)。 />
2.而不是GetFronBufferData
使用GetBackBuffer
并在调用GetRenderTargetData
表面 - 这样你就可以全屏显示。
3.当你需要屏幕的一部分时,你可以调用D3DXLoadSurfaceFromSurface
将整个表面的一部分复制到您的。
4.另一种方法是:在默认内存池中创建具有所需分辨率的渲染目标表面(RT)(POOL_DEFAULT
)并使用感兴趣的区域调用StretchRect
方法 - 这样您就可以将部分屏幕复制到表面,但在默认存储器中将表面复制到GPU上游泳池所以你应该按照已经描述的那样打电话给GetRenderTargetData
。
问候,
Maxim。
Hello.
1. Use system memory pool not scratch (D3DPOOL_SYSTEMMEM
).
2. Instead ofGetFronBufferData
useGetBackBuffer
and after callGetRenderTargetData
of that surface - this way you get whole screen.
3. As you need part of the screen you can callD3DXLoadSurfaceFromSurface
to copy part of the whole surface to your.
4. Another way is: to make a render target surface (RT) with resolution you need in default memory pool (POOL_DEFAULT
) and callStretchRect
method with region of interest - this way you will copy part of the screen into your surface but your surface on GPU in default memory pool so you should callGetRenderTargetData
as already described.
Regards,
Maxim.