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

## Syntax

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

<a id="membersSection" />

### Members

此结构不包含数据成员。

<a id="remarksSection" />

## Remarks

使用此结构来收集屏幕捕获。

你可以通过调用 [XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot) 来截取游戏的屏幕截图。

`XAppCaptureTakeScreenshot` 返回一个或多个本地 ID，你可以通过在调用 [XAppCaptureOpenScreenshotStream](/reference/system/xappcapture/functions/xappcaptureopenscreenshotstream) 时传入这些 ID 来检索屏幕捕获。如果你为 HDR 屏幕截取屏幕截图，将获得两个本地 ID：一个用于 SDR 版本，另一个用于 HDR 版本。

`XAppCaptureOpenScreenshotStream` 返回 `XAppCaptureScreenshotStream` 对象的句柄。你可以通过在调用 [XAppCaptureReadScreenshotStream](/reference/system/xappcapture/functions/xappcapturereadscreenshotstream) 时传入此句柄来读取流的内容。

完成后，通过调用 [XAppCaptureCloseScreenshotStream](/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream) 关闭句柄。

<a id="exampleSection" />

## Example

以下代码示例演示如何将屏幕截图流的内容写入本地文件。

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

## Requirements

**头文件：** XAppCapture.h

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

## See also

[XAppCapture Members](/reference/system/xappcapture/xappcapture_members)\
[XAppCaptureTakeScreenshot](/reference/system/xappcapture/functions/xappcapturetakescreenshot)\
[xappcapturescreenshotformatflag](/reference/system/xappcapture/enums/xappcapturescreenshotformatflag)


## Related topics

- [XAppCapture](/zh-CN/reference/system/xappcapture/xappcapture_members.md)
- [XAppCaptureReadScreenshotStream](/zh-CN/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)
- [XAppCaptureOpenScreenshotStream](/zh-CN/reference/system/xappcapture/functions/xappcaptureopenscreenshotstream.md)
- [XAppCaptureCloseScreenshotStream](/zh-CN/reference/system/xappcapture/functions/xappcaptureclosescreenshotstream.md)
- [XAppCaptureTakeScreenshot](/zh-CN/reference/system/xappcapture/functions/xappcapturetakescreenshot.md)
