PolGraphic
PolGraphic

Reputation: 3364

D3DX11SaveTextureToFile with ID3D11ShaderResourceView

I have the ID3D11ShaderResourceView * textureResView, and I want to save that texture to file. I guess I should first extract the ID3D11Texture2D from it, so I have made a code:

ID3D11Resource * res;
ID3D11Texture2D * tex;
textureResView->GetResource(&res);
res->QueryInterface(&tex);
HRESULT result = D3DX11SaveTextureToFile(
    g_pImmediateContext, tex, D3DX11_IFF_PNG, "name.png");

Unfortunatelly, that returns E_FAIL. What I do wrong?

Upvotes: 1

Views: 3300

Answers (1)

Jinxi
Jinxi

Reputation: 311

Because E_FAIL came back, there was something wrong in the D3DX11SaveTextureToFile(...) function. If you use Windows 8 please use an other function (http://msdn.microsoft.com/en-us/library/windows/desktop/ff476298%28v=vs.85%29.aspx)

But I succest try

HRESULT result = D3DX11SaveTextureToFile(g_pImmediateContext, tex, D3DX11_IFF_PNG, L"name.png");

LPCSTR is a different format to string format, there fore you have to put L infront of the string.

Hope it works

Upvotes: 1

Related Questions