Last active
October 9, 2022 04:26
-
-
Save robmikh/2d70f16f55e408d642a3a738cb8b4071 to your computer and use it in GitHub Desktop.
Save textures in an ImageViewer compatible format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unknwn.h> | |
#include <winrt/base.h> | |
#include <d3d11_4.h> | |
#include <filesystem> | |
#include <fstream> | |
#include <sstream> | |
#include <string> | |
#include <vector> | |
#include <robmikh.common/d3dHelpers.h> | |
inline void SaveRawTexture(winrt::com_ptr<ID3D11Texture2D> const& texture, std::string const& fileName) | |
{ | |
D3D11_TEXTURE2D_DESC desc = {}; | |
texture->GetDesc(&desc); | |
auto filePath = std::filesystem::current_path(); | |
{ | |
std::stringstream fileNameStream; | |
fileNameStream << fileName.c_str() << "_" << desc.Width << "x" << desc.Height << ".bin"; | |
filePath /= fileNameStream.str(); | |
} | |
std::ofstream file(filePath, std::ios::out | std::ios::binary); | |
auto bytes = robmikh::common::uwp::CopyBytesFromTexture(texture); | |
file.write(reinterpret_cast<const char*>(bytes.data()), bytes.size()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment