屏幕截图功能允许开发者对指定参会者的画面进行截图操作,并返回截图的宽度、高度及 Base64 编码的图片数据,开发者可以基于此数据上传或者本地保存图片数据;
特点:
调用 getSnapshot 方法截取当前一帧画面,需要配置SnapshotParams
参数,指定目标画面 ID、图片格式和压缩质量:
// 调用截图方法
const result = await XYClient.getSnapshot({
// 目标参会者的 Layout ID
id: 'Layout ID',
imageType: 'image/jpeg',
compressLevel: 0.85,
});
以下代码展示了一个简单的截图操作示例,包含参数配置、截图操作及图片展示;
async function captureScreenShot(layoutId: string) {
try {
// 配置截图参数
const params = {
id: layoutId,
imageType: 'image/jpeg',
compressLevel: 0.85,
};
// 调用截图方法
const result = await XYClient.getSnapshot(params);
// 处理截图结果
console.log('截图成功!', result);
// 动态展示截图图片
const imgElement = document.createElement('img');
imgElement.src = result.dataURL;
imgElement.style.width = `${result.width}px`;
imgElement.style.height = `${result.height}px`;
// 添加到页面
document.body.appendChild(imgElement);
} catch (error) {
console.error('截图失败:', error);
}
}
// 示例调用
<div onClick={captureScreenShot}>截图</div>;
方法