How to create a texture from a bitmap file?

走远了吗. 提交于 2019-12-12 01:22:27

问题


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:


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.



来源:https://stackoverflow.com/questions/34492720/how-to-create-a-texture-from-a-bitmap-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!