使用DirectX9截取屏幕截图 [英] Taking Screenshot using DirectX9

查看:893
本文介绍了使用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 of GetFronBufferData use GetBackBuffer and after call GetRenderTargetData of that surface - this way you get whole screen.
3. As you need part of the screen you can call D3DXLoadSurfaceFromSurface 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 call StretchRect 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 call GetRenderTargetData as already described.

Regards,
Maxim.


这篇关于使用DirectX9截取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆