Skip to content

ScreenGrab

Chuck Walbourn edited this page Aug 16, 2025 · 2 revisions
DirectXTex

A Direct3D 2D texture save routine for generating a "screenshot" from a render target texture. There is a function that will dump the 2D texture to a .DDS file, and another that will write using WIC (BMP, JPEG, PNG, TIFF, GIF, JPEG-XR / HD Photo, or other WIC supported file container).

These writers do not support array textures, 1D textures, 3D volume textures, cubemaps, or cubemap arrays. The ScreenGrab module is really designed to make a quick and light-weight solution for capturing screenshots at runtime. For more complex textures, see DirectXTex CaptureTexture.

MSAA textures are resolved before being written.

This is the standalone version of these functions. They are also integrated into the DirectX Tool Kit.

Direct3D 9

HRESULT SaveDDSTextureToFile(
    LPDIRECT3DSURFACE9 pSource,
    const wchar_t* fileName);

HRESULT SaveWICTextureToFile(
    LPDIRECT3DSURFACE9 pSource,
    REFGUID guidContainerFormat,
    const wchar_t* fileName,
    const GUID* targetFormat = nullptr,
    std::function<void (IPropertyBag2*)> setCustomProps = nullptr);

Direct3D 11

See DirectX Tool Kit for DX11.

Direct3D 12

See DirectX Tool Kit for DX12.

Returns

These functions will succeed with an S_OK or will return a HRESULT error code (E_INVALIDARG, E_OUTOFMEMORY, E_FAIL, E_POINTER, E_UNEXPECTED, HRESULT_FROM_WIN32(ERROR_INVALID_DATA), HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), or in some cases an HRESULT_FROM_WIN32 result from a Win32 function failure).

Exceptions

These functions are marked noexcept, and do not throw C++ exceptions.

Remarks

These modules are not included in the DirectXTex.lib. To use them directly add the appropriate .cpp and .h file from the ScreenGrab folder to your project -or- use the DirectX Tool Kit.

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One
  • Xbox Series X|S
  • Windows Subsystem for Linux

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v20
  • GCC 10.5, 11.4, 12.3, 13.3, 14.2
  • MinGW 12.2, 13.2
  • CMake 3.21

Related Projects

DirectXTex Rust bindings

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXMesh

DirectXMath

Tools

Test Suite

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally