HarmonyOS 屏幕截图?

我有个功能,需要对应用当前页面的某个component截图,如下段代码中,需要在点击按钮的时候,将Scroll屏幕可见的内容截图,比如用户滑动到展示第10到第18条,那截图内容就是第10到第18条,而不是从第一条开始,请问onClick应该怎么写

@Entry
@Component
struct SnapShotExample{
  @State items:string[] = ['1', '2', '3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32']
  build() {
    Column() {
      Text('我是标题')
        .width('100%').height(100).textAlign(TextAlign.Center).fontColor(Color.Black).backgroundColor(Color.Gray)
      Scroll() {
        Column() {
          ForEach(this.items, (item: string) => {
            Text('我是内容' + item).width('100%').height(50).fontColor(Color.Red)
          })
        }.width('100%')
      }.width('100%').layoutWeight(1)
      Blank().width('100%').height(1).backgroundColor(Color.Black)
      Button('点击截图').width(100).height(45).onClick(()=>{
        //TODO
      })
    }.width('100%').height('100%')
  }
}
阅读 445
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进