您可以用componentSnapshot.createFromBuilder可以实现,将需要截图的组件用CustomBuilder的形式包裹Button("点击截图").onClick(() => { componentSnapshot.createFromBuilder(() => { this.RandomBuilder() }, (error: Error, pixmap: image.PixelMap) => { if (error) { console.log("error: " + JSON.stringify(error)) return; } this.pixmap = pixmap // save pixmap to file // .... // get component size and location let info = componentUtils.getRectangleById("builder") console.log(info.size.width + ' ' + info.size.height + ' ' + info.localOffset.x + ' ' + info.localOffset.y + ' ' + info.windowOffset.x + ' ' + info.windowOffset.y) this.shotWidth = px2vp(info.size.width) this.shotHeight = px2vp(info.size.height) }) })参考此链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-componentsnapshot-V5\#componentsnapshotcreatefrombuilder
您可以用componentSnapshot.createFromBuilder可以实现,将需要截图的组件用CustomBuilder的形式包裹
参考此链接:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-componentsnapshot-V5\#componentsnapshotcreatefrombuilder