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

# XAppCaptureScreenshotStream

> XAppCaptureScreenshotStream

# XAppCaptureScreenshotStream

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

## 語法

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

### 成員

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

## 備註

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

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

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

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

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

## 範例

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

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

}

```

## 需求

**標頭：** XAppCapture.h

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

## 另請參閱

[XAppCapture 成員](https://docs.xbox.com/zh-TW/reference/system/xappcapture/xappcapture_members.md)\
[XAppCaptureTakeScreenshot](https://docs.xbox.com/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot.md)\
[xappcapturescreenshotformatflag](https://docs.xbox.com/zh-TW/reference/system/xappcapture/enums/xappcapturescreenshotformatflag.md)


## Related topics

- [XAppCapture (API 內容)](https://docs.xbox.com/zh-TW/reference/system/xappcapture/xappcapture_members.md)
- [XAppCaptureReadScreenshotStream](https://docs.xbox.com/zh-TW/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)
- [XAppCaptureOpenScreenshotStream](https://docs.xbox.com/zh-TW/reference/system/xappcapture/functions/xappcaptureopenscreenshotstream.md)
- [XAppCaptureCloseScreenshotStream](https://docs.xbox.com/zh-TW/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream.md)
- [XAppCaptureTakeScreenshot](https://docs.xbox.com/zh-TW/reference/system/xappcapture/functions/xappcapturetakescreenshot.md)
