D3D10 截图功能 保存Texture到本地

Date 20200311 By Wjb

直接上代码:

        ID3D10Resource* pScreen;
		mRenderTargetView->GetResource(&pScreen);
		D3D10_TEXTURE2D_DESC texDesc;
		texDesc.ArraySize = 1;
		texDesc.CPUAccessFlags = 0;
		texDesc.Width = (unsigned int)mClientWidth;
		texDesc.Height = (unsigned int)mClientHeight;;
		texDesc.SampleDesc.Count = 8;
		texDesc.SampleDesc.Quality = 0;
		texDesc.ArraySize = 1;
		texDesc.MipLevels = 1;
		texDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
		texDesc.SampleDesc.Count = 1;
		texDesc.SampleDesc.Quality = 0;
		texDesc.Usage = D3D10_USAGE_DEFAULT;
		texDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;

		ID3D10Texture2D *texture;
		HRESULT hr = md3dDevice->CreateTexture2D(&texDesc, 0, &texture);
		md3dDevice->CopyResource(texture, pScreen);

		char filename [245];
		sprintf(filename, "TestFile%d.dds", name);
		hr = D3DX10SaveTextureToFileA(texture, D3DX10_IFF_DDS, filename);

		texture->Release();
		pScreen->Release();

我保存事DDS格式文件,在VS中打开效果如下图所以

D3D10 截图功能 保存Texture到本地_第1张图片

我附了功能源码,环境VS2013 d3d10。下载地址:

你可能感兴趣的:(D3D10 截图功能 保存Texture到本地)