[英]Converting DirectX11 ID3D11Texture2D from Shader into OpenCV IplImage
[英]How to get the DirectX::Image (from DirectXTex) structure based on ID3D11Texture2D?
我有一个自定义纹理类:
class Texture{
ID3D11Texture2D * renderTargetTexture;
public:
...
void saveToTGA(std::wstring filePath);
};
我正在将此纹理用作渲染过程之间的渲染目标。 我想编写一个saveToTGA(std::wstring filePath)
方法,该方法将纹理保存到文件( saveToTGA(std::wstring filePath)
屏幕截图)。
MSDN说D3DX11SaveTextureToFile(...)
已D3DX11SaveTextureToFile(...)
所以我决定按照他们的建议使用DirectXTex库。
我知道我必须使用:
DirectX::Image image = ...
DirectX::SaveToTGAFile(image, filePath.c_str());
但是问题是:如何基于ID3D11Texture2D
获取DirectX::Image
(从DirectXTex)结构?
从MSDN文档中,您可以使用
我们建议您在Blockquote中使用DirectXTex库,CaptureTexture,然后使用SaveToXXXFile(其中XXX是WIC,DDS或TGA; WIC不支持DDS和TGA; D3DX 9支持TGA作为游戏的通用美术源格式)。
因此,首先您使用以下命令从纹理缓冲区捕获纹理
HRESULT hr = DirectX::CaptureTexture(m_D3D->GetDevice(), m_D3D->GetDeviceContext(), resourceContext, image);
然后执行保存功能
hr = DirectX::SaveToDDSFile(image.GetImages(),image.GetImageCount(), image.GetMetadata(), DirectX::DDS_FLAGS_NONE, Filename);
请参阅此参考https://github.com/Microsoft/DirectXTex/wiki/CaptureTexture
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.