How to create a texture from a bitmap file?

2019-09-05 19:14发布

Can you please help me in finding the equivalent DX12 API/sample code by which I could load a bitmap and create a texture ?

For DX11 it is D3DX11CreateShaderResourceViewFromFile and for DX9 it is D3DXCreateTextureFromFileEx

1条回答
做个烂人
2楼-- · 2019-09-05 20:06

You can use the following functions from DirectXTK, as well as many other.

// Standard version
HRESULT __cdecl LoadWICTextureFromMemory(
    _In_ ID3D12Device* d3dDevice,
    _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
    size_t wicDataSize,
    _Outptr_ ID3D12Resource** texture,
    std::unique_ptr<uint8_t[]>& decodedData,
    D3D12_SUBRESOURCE_DATA& subresource,
    size_t maxsize = 0);

HRESULT __cdecl LoadWICTextureFromFile(
    _In_ ID3D12Device* d3dDevice,
    _In_z_ const wchar_t* szFileName,
    _Outptr_ ID3D12Resource** texture,
    std::unique_ptr<uint8_t[]>& decodedData,
    D3D12_SUBRESOURCE_DATA& subresource,
    size_t maxsize = 0);

Alternatively you can use Windows Imaging Component to write your own implementation, especially if you would like to have more control.

查看更多
登录 后发表回答