> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XAppCaptureScreenshotStream

> XAppCaptureScreenshotStream

# XAppCaptureScreenshotStream

Represents a screenshot stream.

<a id="syntaxSection" />

## Syntax

```cpp theme={null}
typedef struct XAppCaptureScreenshotStream {  
} XAppCaptureScreenshotStream  
```

<a id="membersSection" />

### Members

This structure contains no data members.

<a id="remarksSection" />

## Remarks

Use this structure to collect screen captures.

You can take a screenshot of the game by calling [XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot).

`XAppCaptureTakeScreenshot` returns one or more local IDs, which you can use to retrieve a screen capture by passing it in a call to [XAppCaptureOpenScreenshotStream](/reference/system/xappcapture/functions/xappcaptureopenscreenshotstream). You will get two local IDs if you take a screenshot of an HDR screenk: one for the SDR version, and one for HDR version.

`XAppCaptureOpenScreenshotStream` returns a handle to the `XAppCaptureScreenshotStream` object. You can use this handle to read the content of the stream by passing it in a call to [XAppCaptureReadScreenshotStream](/reference/system/xappcapture/functions/xappcapturereadscreenshotstream).

When you're done, you close the handle by calling [XAppCaptureCloseScreenshotStream](/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream).

<a id="exampleSection" />

## Example

The following code example demonstrates how to write the content of the screenshot stream to a local file.

```cpp theme={null}
void WriteScreenshotStreamToFile(_In_ const char* screenshotLocalId, _In_ XAppCaptureScreenshotFormatFlag screenshotFormat, _In_ const char* filePath)
{
    const int MAX_DATA = 1024;
    XAppCaptureScreenshotStreamHandle handle = nullptr;
    BYTE buffer[MAX_DATA];
    HANDLE file = INVALID_HANDLE_VALUE;
    UINT64 totalBytesRead = 0;
    UINT64 totalBytesToRead = 0;

    if (FAILED_LOG(XAppCaptureOpenScreenshotStream(screenshotLocalId, screenshotFormat, &handle, &totalBytesToRead)))
    {
        return;
    }

    appLog.AddLog("%I64d bytes returned\n", totalBytesToRead);

    file = CreateFileA(filePath, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    if (file == INVALID_HANDLE_VALUE)
    {
        appLog.AddLog("Could not create %s\n", filePath);
        goto Cleanup;
    }

    while (totalBytesRead < totalBytesToRead)
    {
        uint32_t bytesRead = 0;
        DWORD bytesWritten = 0;

        if (FAILED_LOG(XAppCaptureReadScreenshotStream(handle, totalBytesRead, sizeof(buffer), buffer, &bytesRead)))
        {
            goto Cleanup;
        }

        BOOL result = WriteFile(file, buffer, bytesRead, &bytesWritten, NULL );
        if (!result)
        {
            appLog.AddLog("Failed to write to %s\n", filePath);
            goto Cleanup;
        }

        totalBytesRead += bytesRead;
    }

Cleanup:
    if (handle != nullptr)
    {
        FAILED_LOG(XAppCaptureCloseScreenshotStream(handle));
    }
    if (file != INVALID_HANDLE_VALUE)
    {
        CloseHandle(file);
    }
    appLog.AddLog("Wrote out %I64d bytes to %s\n", totalBytesRead, filePath);

}

```

<a id="requirementsSection" />

## Requirements

**Header:** XAppCapture.h

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## See also

[XAppCapture Members](/reference/system/xappcapture/xappcapture_members)\
[XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot)\
[xappcapturescreenshotformatflag](/reference/system/xappcapture/enums/xappcapturescreenshotformatflag)


## Related topics

- [XAppCapture](/reference/system/xappcapture/xappcapture_members.md)
- [XAppCaptureOpenScreenshotStream](/reference/system/xappcapture/functions/xappcaptureopenscreenshotstream.md)
- [XAppCaptureReadScreenshotStream](/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)
- [XAppCaptureCloseScreenshotStream](/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream.md)
- [XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot.md)
