DirectX11 CreateWICTextureFromMemory Using PNG

北城余情 提交于 2019-12-06 09:20:51

Hopefully someone trying to do the same thing will find this solution.

Below is the code I used to solve this problem.

std::basic_ifstream<unsigned char> file("image.png", std::ios::binary);

if (file.is_open())
{
    file.seekg(0,std::ios::end);
    int length = file.tellg();
    file.seekg(0,std::ios::beg);

    unsigned char* buffer = new unsigned char[length];
    file.read(&buffer[0],length);
    file.close();

    HRESULT hr;
    hr = DirectX::CreateWICTextureFromMemory(_D3D->GetDevice(), _D3D->GetDeviceContext(), &buffer[0], (size_t)length, nullptr, &srv, NULL);
}

The important change being (size_t)length in CreateWICTextureFromMemory

It was indeed a stupid error.

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