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

# XAppCaptureOpenScreenshotStream

> XAppCaptureOpenScreenshotStream

# XAppCaptureOpenScreenshotStream

打开屏幕截图流。

## Syntax

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

### Parameters

*localId*   \_In\_\
类型：char\*

调用 [XAppCaptureTakeScreenshot](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcapturetakescreenshot.md) 之后在 [XAppCaptureTakeScreenshotResult](https://docs.xbox.com/zh-CN/reference/system/xappcapture/structs/xappcapturetakescreenshotresult.md) 中返回的屏幕截图本地 ID。

*screenshotFormat*   \_In\_\
类型：[XAppCaptureScreenshotFormatFlag](https://docs.xbox.com/zh-CN/reference/system/xappcapture/enums/xappcapturescreenshotformatflag.md)

调用 [XAppCaptureTakeScreenshot](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcapturetakescreenshot.md) 之后在 [XAppCaptureTakeScreenshotResult](https://docs.xbox.com/zh-CN/reference/system/xappcapture/structs/xappcapturetakescreenshotresult.md) 中返回的屏幕截图格式标志。

*handle*   \_Out\_\
类型：XAppCaptureScreenshotStreamHandle\*

打开流后返回的屏幕截图流句柄。

*totalBytes*   \_Out\_opt\_\
类型：uint64\_t\*

流中字节的总数。

### Return value

类型：HRESULT

函数结果。

## Remarks

> [!NOTE]
>
> 此函数在时间敏感线程上调用不安全。有关详细信息，请参阅[时间敏感线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。

无法从游戏分区访问屏幕截图，因此必须打开流以检索用户拍摄的或通过 [XAppCaptureTakeScreenshot](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcapturetakescreenshot.md) 拍摄的屏幕截图。[XAppCaptureTakeScreenshot](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcapturetakescreenshot.md) 会在其结果中返回 *localID*，此函数会使用该 ID 来检索相应的屏幕截图。只要屏幕截图保留在磁盘上，*localID* 就有效。主机上用于存储屏幕截图的空间有限。分配的空间用完后，较旧的屏幕截图会被删除。这可能会导致打开屏幕截图的函数无法命中某个 localID。打开流后，可以使用 [XAppCaptureReadScreenShotStream](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md) 读取屏幕截图。最后，每个流都需要使用 [XAppCaptureCloseScreenshotStream](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream.md) 关闭，以避免内存泄漏。

```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

**头文件：** XAppCapture.h

**库：** xgameruntime.lib

**受支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## Conceptual documentation

* [时间敏感线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[GameDVR 概述](https://docs.xbox.com/zh-CN/build/console-features/game-dvr/gamedvr-broadcast.md)\
[XAppCapture Members](https://docs.xbox.com/zh-CN/reference/system/xappcapture/xappcapture_members.md)\
[XAppCaptureReadScreenShotStream](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)\
[XAppCaptureTakeScreenshot](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcapturetakescreenshot.md)\
[XAppCaptureCloseScreenshotStream](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream.md)


## Related topics

- [XAppCaptureScreenshotStream](https://docs.xbox.com/zh-CN/reference/system/xappcapture/structs/xappcapturescreenshotstream.md)
- [XAppCaptureReadScreenshotStream](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)
- [XAppCapture（API 内容）](https://docs.xbox.com/zh-CN/reference/system/xappcapture/xappcapture_members.md)
- [在 Unity 项目中使用 GDK API 的 C# 包装器](https://docs.xbox.com/zh-CN/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XAppCaptureCloseScreenshotStream](https://docs.xbox.com/zh-CN/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream.md)
