如下demo,对XComponent截图失败
snapshot = (): image.PixelMap | null => {
if (this.surfaceId?.length !== 0) {
const region: image.Region = {
x: 0,
y: 0,
size: {
width: this.windowRect[0],
height: this.windowRect[1]
}
};
// 在EntryAbility设置了沉浸式页面,所以size是屏幕宽高,不然接口crash
return image.createPixelMapFromSurfaceSync(this.surfaceId, region);
}
return null;
}
问题根因:image.createPixelMapFromSurfaceSync(this.surfaceId, region)截图的region需要在组件区域内,报错原因的region的size设置过大。
可参考如下demo: