# 本地截图上传 (/zh-CN/api-reference/rtc/harmonyos/video/video-prenpro/snapshot)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

<a id="toc_snapshot"></a>

<a id="api_irtcengine_enablecontentinspect"></a>

<a id="ariaid-title2"></a>

## enableContentInspect [#enablecontentinspect]

开启/关闭本地截图上传。

<a id="api_irtcengine_enablecontentinspect__prototype"></a>

```ts
public abstract enableContentInspect(enabled:boolean,config:ContentInspectConfig):number;
```

<a id="api_irtcengine_enablecontentinspect__detailed_desc"></a>

开启本地截图上传后，SDK 会根据你在 [ContentInspectConfig](/zh-CN/api-reference/rtc/harmonyos/class-contentinspectconfig) 中设置的模块类型和频率对本地用户发送的视频进行截图和上传。截图完成后，声网服务器会以 HTTPS 请求的形式，向你的服务器发送回调通知，并将所有截图发送至你指定的第三方云存储。

<a id="api_irtcengine_enablecontentinspect__timing"></a>

### 调用时机 [#调用时机]

加入频道前后均可调用。

<a id="api_irtcengine_enablecontentinspect__restriction"></a>

### 调用限制 [#调用限制]

- 调用该方法前，请确保已[联系技术支持](https://ticket.shengwang.cn/)开通本地截图上传服务。
- 视频审核模块选择声网自研插件截图上传（SUPERVISE）时需集成本地截图上传动态库 `agora_content_inspect_extension.so`，如果删除该动态库会导致无法正常开启本地截图上传功能。

<a id="api_irtcengine_enablecontentinspect__parameters"></a>

### 参数 [#参数]

<ParameterList>
<a id="enabled"></a>
<Parameter name="enabled">

设置是否开启本地截图上传：

- `true`：开启本地截图上传。
- `false`：关闭本地截图上传。

</Parameter>
<a id="config"></a>
<Parameter name="config">

本地截图上传配置。详见 [ContentInspectConfig](/zh-CN/api-reference/rtc/harmonyos/class-contentinspectconfig)。

</Parameter>
</ParameterList>

<a id="api_irtcengine_enablecontentinspect__return_values"></a>

### 返回值 [#返回值]

- 0: 方法调用成功。
- &lt; 0: 方法调用失败。详见[错误码](/zh-CN/api-reference/rtc/error-code)了解详情和解决建议。

### 所属接口类 [#所属接口类]

- [RtcEngine](/zh-CN/api-reference/rtc/harmonyos/rtc-interface-class#class_irtcengine)

<a id="api_irtcengine_takesnapshot"></a>

<a id="ariaid-title3"></a>

## takeSnapshot [#takesnapshot]

获取视频截图。

<a id="api_irtcengine_takesnapshot__prototype"></a>

```ts
public abstract takeSnapshot(uid: number, filePath: string): number;
```

<a id="api_irtcengine_takesnapshot__detailed_desc"></a>

该方法用于对指定用户的视频流进行截图，生成一张 JPG 格式的图片，并保存至指定的路径。

<a id="api_irtcengine_takesnapshot__timing"></a>

### 调用时机 [#调用时机-1]

该方法需要在加入频道后调用。

<a id="api_irtcengine_takesnapshot__restriction"></a>

### 调用限制 [#调用限制-1]

- 该方法是异步操作，调用返回时 SDK 并没有真正获取截图。
- 该方法用于本地视频截图时，是对 [ChannelMediaOptions](/zh-CN/api-reference/rtc/harmonyos/class-channelmediaoptions) 中指定发布的视频流进行截图。
- 如果用户的视频经过前处理，例如，添加了水印或美颜，生成的截图会包含前处理效果。

<a id="api_irtcengine_takesnapshot__related"></a>

### 相关回调 [#相关回调]

成功调用该方法后，SDK 会触发 [onSnapshotTaken](/zh-CN/api-reference/rtc/harmonyos/video/video-prenpro/snapshot#callback_irtcengineeventhandler_onsnapshottaken) 回调，报告截图是否成功和获取截图的详情。

<a id="api_irtcengine_takesnapshot__parameters"></a>

### 参数 [#参数-1]

<ParameterList>
<a id="uid"></a>
<Parameter name="uid">

用户 ID。如果要对本地用户的视频截图，则设为 0。

</Parameter>
<a id="filepath"></a>
<Parameter name="filePath">

截图的本地保存路径，需精确到文件名及格式，例如：

- HarmonyOS: `/data/app/el2/100/base/PACKAGENAME/haps/ENTRYNAME/files/example.jpg`

:::caution
注意： 请确保目录存在且可写。
:::

</Parameter>
</ParameterList>

<a id="api_irtcengine_takesnapshot__return_values"></a>

### 返回值 [#返回值-1]

- 0: 方法调用成功。
- &lt; 0: 方法调用失败。详见[错误码](/zh-CN/api-reference/rtc/error-code)了解详情和解决建议。

### 所属接口类 [#所属接口类-1]

- [RtcEngine](/zh-CN/api-reference/rtc/harmonyos/rtc-interface-class#class_irtcengine)

<a id="api_irtcengineex_takesnapshotex"></a>

<a id="ariaid-title4"></a>

## takeSnapshotEx [#takesnapshotex]

使用连接 ID 获取视频截图。

<a id="api_irtcengineex_takesnapshotex__prototype"></a>

```ts
public abstract takeSnapshotEx(connection:RtcConnection,uid:number,filePath:string):number;
```

<a id="api_irtcengineex_takesnapshotex__detailed_desc"></a>

该方法用于对指定用户的视频流进行截图，生成一张 JPG 格式的图片，并保存至指定的路径。

<a id="api_irtcengineex_takesnapshotex__timing"></a>

### 调用时机 [#调用时机-2]

该方法需要在 [joinChannelEx](/zh-CN/api-reference/rtc/harmonyos/channel#api_irtcengineex_joinchannelex) 后调用。

<a id="api_irtcengineex_takesnapshotex__restriction"></a>

### 调用限制 [#调用限制-2]

- 该方法是异步操作，调用返回时 SDK 并没有真正获取截图。
- 该方法用于本地视频截图时，是对 [ChannelMediaOptions](/zh-CN/api-reference/rtc/harmonyos/class-channelmediaoptions) 中指定发布的视频流进行截图。
- 如果用户的视频经过前处理，例如，添加了水印或美颜，生成的截图会包含前处理效果。

<a id="api_irtcengineex_takesnapshotex__related"></a>

### 相关回调 [#相关回调-1]

成功调用该方法后，SDK 会触发 [onSnapshotTaken](/zh-CN/api-reference/rtc/harmonyos/video/video-prenpro/snapshot#callback_irtcengineeventhandler_onsnapshottaken) 回调，报告截图是否成功和获取截图的详情。

<a id="api_irtcengineex_takesnapshotex__parameters"></a>

### 参数 [#参数-2]

<ParameterList>
<a id="connection"></a>
<Parameter name="connection">

Connection 信息。详见 [RtcConnection](/zh-CN/api-reference/rtc/harmonyos/class-rtcconnection)。

</Parameter>
<a id="uid-1"></a>
<Parameter name="uid">

用户 ID。如果要对本地用户的视频截图，则设为 0。

</Parameter>
<a id="filepath-1"></a>
<Parameter name="filePath">

截图的本地保存路径，需精确到文件名及格式，例如：

- HarmonyOS: `/data/app/el2/100/base/PACKAGENAME/haps/ENTRYNAME/files/example.jpg`

:::caution
注意： 请确保目录存在且可写。
:::

</Parameter>
</ParameterList>

<a id="api_irtcengineex_takesnapshotex__return_values"></a>

### 返回值 [#返回值-2]

- 0: 方法调用成功。
- &lt; 0: 方法调用失败。详见[错误码](/zh-CN/api-reference/rtc/error-code)了解详情和解决建议。

<a id="callback_irtcengineeventhandler_onsnapshottaken"></a>

<a id="ariaid-title5"></a>

## onSnapshotTaken [#onsnapshottaken]

视频截图结果回调。

<a id="callback_irtcengineeventhandler_onsnapshottaken__prototype"></a>

```ts
onSnapshotTaken?:(uid:number, filePath:string , width:number, height:number, errCode:number) => void
```

<a id="callback_irtcengineeventhandler_onsnapshottaken__detailed_desc"></a>

### 详情 [#详情]

成功调用 [takeSnapshot](/zh-CN/api-reference/rtc/harmonyos/video/video-prenpro/snapshot#api_irtcengine_takesnapshot) 后，SDK 触发该回调报告截图是否成功和获取截图的详情。

<a id="callback_irtcengineeventhandler_onsnapshottaken__parameters"></a>

### 参数 [#参数-3]

<ParameterList>
<a id="uid-2"></a>
<Parameter name="uid">

用户 ID。如果 uid 为 0，表示本地用户。

</Parameter>
<a id="filepath-2"></a>
<Parameter name="filePath">

截图的本地保存路径。

</Parameter>
<a id="width"></a>
<Parameter name="width">

图片宽度（px）。

</Parameter>
<a id="height"></a>
<Parameter name="height">

图片高度（px）。

</Parameter>
<a id="errcode"></a>
<Parameter name="errCode">

截图成功的提示或失败的原因。

- 0：截图成功。
- &lt; 0: 截图失败。

  - -1：写入文件失败或 JPEG 编码失败。
  - -2：takeSnapshot 方法调用后 1 秒内没有收到指定用户的视频帧。可能的原因有：本地采集停止、远端停止发布或者视频数据处理堵塞。
  - -3：takeSnapshot 方法调用过于频繁。

</Parameter>
</ParameterList>

### 所属接口类 [#所属接口类-2]

- [IRtcEngineEventHandler](/zh-CN/api-reference/rtc/harmonyos/rtc-interface-class#class_irtcengineeventhandler)
