HarmonyOS 截取控件内容不太够,怎么截长图?

如题:HarmonyOS 截取控件内容不太够,怎么截长图?

阅读 426
1 个回答

您可以用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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进