> ## 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.

# XAppCaptureOpenScreenshotStream

> XAppCaptureOpenScreenshotStream

# XAppCaptureOpenScreenshotStream

Opens a screenshot stream.

## Syntax

```cpp theme={null}
HRESULT XAppCaptureOpenScreenshotStream(  
         const char* localId,  
         XAppCaptureScreenshotFormatFlag screenshotFormat,  
         XAppCaptureScreenshotStreamHandle* handle,  
         uint64_t* totalBytes  
)  
```

### Parameters

*localId*   \_In\_\
Type: char\*

Local ID of the screenshot returned in [XAppCaptureTakeScreenshotResult](/reference/system/xappcapture/structs/xappcapturetakescreenshotresult) after calling [XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot).

*screenshotFormat*   \_In\_\
Type: [XAppCaptureScreenshotFormatFlag](/reference/system/xappcapture/enums/xappcapturescreenshotformatflag)

Screenshot format flag returned in [XAppCaptureTakeScreenshotResult](/reference/system/xappcapture/structs/xappcapturetakescreenshotresult) after calling [XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot).

*handle*   \_Out\_\
Type: XAppCaptureScreenshotStreamHandle\*

Screenshot stream handle returned as a result of opening the stream.

*totalBytes*   \_Out\_opt\_\
Type: uint64\_t\*

Total number of bytes in the stream.

### Return value

Type: HRESULT

Function result.

## Remarks

<Note>This function isn't safe to call on a time-sensitive thread. For more information, see [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads).</Note>

Screenshots are not accessible from the game partition and so you must open a stream in order to retrieve screenshots taken by the user or with [XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot). [XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot) returns a *localID* in its result which is used in this function to retrieve the proper screenshot. The *localID* will be valid as long as the screenshot is retained on disk. There is only a limited amount of space on the console in which screenshots are stored. Older screenshots will be deleted when the allotted space is filled. This could potentially cause the open screenshot function to miss on a localID. After opening the stream you may read the screenshot with [XAppCaptureReadScreenShotStream](/reference/system/xappcapture/functions/xappcapturereadscreenshotstream). Finally every stream needs to be closed with [XAppCaptureCloseScreenshotStream](/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream) in order to avoid a memory leak.

```cpp theme={null}
XAppCaptureTakeScreenshotResult takeScreenshotResult = {0};
XAppCaptureScreenshotStreamHandle handle = nullptr;
UINT64 totalBytesToRead = 0;
XAppCaptureScreenshotFormatFlag screenshotFormat = XAppCaptureScreenshotFormatFlag::SDR;
bool hdrAvailable = false;

/* ... obtain takeScreenshotResult with XAppCaptureTakeScreenshot. Refer to corresponding documentation ... */

hdrAvailable = static_cast<bool>(takeScreenshotResult.availableScreenshotFormats & XAppCaptureScreenshotFormatFlag::HDR);

/* Note: It is optional to obtain the HDR screenshot, if HDR is available. You will need to call XAppCaptureOpenScreenshotStream twice to obtain both SDR and HDR screenshots */
if (hdrAvailable)
{
    screenshotFormat = XAppCaptureScreenshotFormatFlag::HDR;
}

if (FAILED_LOG(XAppCaptureOpenScreenshotStream(takeScreenshotResult.localId, screenshotFormat, &handle, &totalBytesToRead)))
{
    return;
}

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

/* You must always call XAppCaptureCloseScreenshotStream on an open XAppCaptureScreenshotStreamHandle to avoid a memory leak */
if (handle != nullptr)
{
    XAppCaptureCloseScreenshotStream(handle);
}

```

## Requirements

**Header:** XAppCapture.h

**Library:** xgameruntime.lib

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

## Conceptual documentation

* [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[GameDVR Overview](/build/console-features/game-dvr/gamedvr-broadcast)\
[XAppCapture Members](/reference/system/xappcapture/xappcapture_members)\
[XAppCaptureReadScreenShotStream](/reference/system/xappcapture/functions/xappcapturereadscreenshotstream)\
[XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot)\
[XAppCaptureCloseScreenshotStream](/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream)


## Related topics

- [XAppCaptureScreenshotStream](/reference/system/xappcapture/structs/xappcapturescreenshotstream.md)
- [XAppCaptureReadScreenshotStream](/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)
- [XAppCapture](/reference/system/xappcapture/xappcapture_members.md)
- [Unity C# API wrappers for the GDK](/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XAppCaptureCloseScreenshotStream](/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream.md)
