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

代表螢幕擷取畫面資料流。

<a id="syntaxSection" />

## 語法

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

<a id="membersSection" />

### 成員

此結構不包含任何資料成員。

<a id="remarksSection" />

## 備註

使用此結構來收集螢幕擷取。

您可以呼叫 [XAppCaptureTakeScreenshot](/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot) 來擷取遊戲的螢幕擷取畫面。

`XAppCaptureTakeScreenshot` 會傳回一個或多個本機識別碼，您可以在呼叫 [XAppCaptureOpenScreenshotStream](/zh-TW/reference/system/xappcapture/functions/xappcaptureopenscreenshotstream) 時傳入，以擷取螢幕擷取畫面。如果您擷取 HDR 畫面的螢幕擷取畫面，將取得兩個本機識別碼：一個用於 SDR 版本，另一個用於 HDR 版本。

`XAppCaptureOpenScreenshotStream` 會傳回 `XAppCaptureScreenshotStream` 物件的控制代碼。您可以在呼叫 [XAppCaptureReadScreenshotStream](/zh-TW/reference/system/xappcapture/functions/xappcapturereadscreenshotstream) 時傳入此控制代碼，以讀取資料流的內容。

完成後，請呼叫 [XAppCaptureCloseScreenshotStream](/zh-TW/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream) 來關閉控制代碼。

<a id="exampleSection" />

## 範例

下列程式碼範例示範如何將螢幕擷取畫面資料流的內容寫入本機檔案。

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

## 需求

**標頭：** XAppCapture.h

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

## 另請參閱

[XAppCapture 成員](/zh-TW/reference/system/xappcapture/xappcapture_members)\
[XAppCaptureTakeScreenshot](/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot)\
[xappcapturescreenshotformatflag](/zh-TW/reference/system/xappcapture/enums/xappcapturescreenshotformatflag)


## Related topics

- [XAppCaptureScreenshotStream](/ko/reference/system/xappcapture/structs/xappcapturescreenshotstream.md)
- [XAppCapture](/reference/system/xappcapture/xappcapture_members.md)
