我有个功能,需要对应用当前页面的某个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%')
}
}
看一下组件截图,组件截图只能够截取组件大小的区域应该是只有视图部分,如果组件的绘制超出了它的区域,或子组件的绘制超出了父组件的区域,这些在组件区域外绘制的内容不会在截图中呈现
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-componentsnapshot-V5