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

開啟螢幕擷取畫面串流。

## 語法

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

### 參數

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

呼叫 [XAppCaptureTakeScreenshot](/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot) 之後，在 [XAppCaptureTakeScreenshotResult](/zh-TW/reference/system/xappcapture/structs/xappcapturetakescreenshotresult) 中傳回的螢幕擷取畫面本機 ID。

*screenshotFormat*   \_In\_\
類型：[XAppCaptureScreenshotFormatFlag](/zh-TW/reference/system/xappcapture/enums/xappcapturescreenshotformatflag)

呼叫 [XAppCaptureTakeScreenshot](/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot) 之後，在 [XAppCaptureTakeScreenshotResult](/zh-TW/reference/system/xappcapture/structs/xappcapturetakescreenshotresult) 中傳回的螢幕擷取畫面格式旗標。

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

開啟串流後傳回的螢幕擷取畫面串流控制代碼。

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

串流中的位元組總數。

### 傳回值

類型：HRESULT

函式結果。

## 備註

<Note>在時間敏感執行緒上呼叫此函式並不安全。如需詳細資訊，請參閱[時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

無法從遊戲分割區存取螢幕擷取畫面，因此您必須開啟串流，才能擷取使用者所拍攝或使用 [XAppCaptureTakeScreenshot](/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot) 拍攝的螢幕擷取畫面。[XAppCaptureTakeScreenshot](/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot) 會在其結果中傳回 *localID*，此函式會使用它來擷取正確的螢幕擷取畫面。只要螢幕擷取畫面保留在磁碟上，*localID* 就會有效。主機上用來儲存螢幕擷取畫面的空間有限。當配置的空間已滿時，將會刪除較舊的螢幕擷取畫面。這可能會導致開啟螢幕擷取畫面函式找不到 localID。開啟串流之後，您可以使用 [XAppCaptureReadScreenShotStream](/zh-TW/reference/system/xappcapture/functions/xappcapturereadscreenshotstream) 讀取螢幕擷取畫面。最後，每個串流都必須使用 [XAppCaptureCloseScreenshotStream](/zh-TW/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream) 關閉，以避免記憶體流失。

```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);
}

```

## 需求

**標頭：** XAppCapture.h

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 另請參閱

[GameDVR 概觀](/zh-TW/build/console-features/game-dvr/gamedvr-broadcast)\
[XAppCapture 成員](/zh-TW/reference/system/xappcapture/xappcapture_members)\
[XAppCaptureReadScreenShotStream](/zh-TW/reference/system/xappcapture/functions/xappcapturereadscreenshotstream)\
[XAppCaptureTakeScreenshot](/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot)\
[XAppCaptureCloseScreenshotStream](/zh-TW/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream)


## Related topics

- [XAppCaptureOpenScreenshotStream](/reference/system/xappcapture/functions/xappcaptureopenscreenshotstream.md)
- [XAppCaptureScreenshotStream](/reference/system/xappcapture/structs/xappcapturescreenshotstream.md)
- [XAppCaptureReadScreenshotStream](/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)
