HarmonyOS 鸿蒙Next如何对某个组件进行截图?
HarmonyOS 鸿蒙Next如何对某个组件进行截图?
如何对某个组件进行截图?
关于HarmonyOS 鸿蒙Next如何对某个组件进行截图?的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
3 回复
import componentSnapshot from '@ohos.arkui.componentSnapshot'
import image from '@ohos.multimedia.image'
@Entry
@Component
export struct SnapshotExample {
@State pixmap: image.PixelMap | undefined = undefined
build() {
Column({ space: 30 }) {
Column() {
Text(“张三”)
.padding(10)
.fontColor(Color.White)
.backgroundColor(Color.Blue)
Text(“李四”)
.padding(10)
.fontColor(Color.White)
.backgroundColor(Color.Red)
}
.id(“root”)
.width(200)
.height(200)
.justifyContent(FlexAlign.SpaceEvenly)
.backgroundColor(Color.Yellow)
Button(<span class="hljs-string"><span class="hljs-string">"截图"</span></span>).onClick(() => {
componentSnapshot.get(<span class="hljs-string"><span class="hljs-string">"root"</span></span>, ((err: <span class="hljs-built_in"><span class="hljs-built_in">Error</span></span>, pixmap: image.PixelMap) => {
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (err) {
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span>
}
<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.pixmap = pixmap
}))
})
Image(<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.pixmap).width(<span class="hljs-number"><span class="hljs-number">200</span></span>)
.height(<span class="hljs-number"><span class="hljs-number">200</span></span>)
.border({width:<span class="hljs-number"><span class="hljs-number">1</span></span>,color:Color.Gray})
}.height(<span class="hljs-string"><span class="hljs-string">"100%"</span></span>)
.width(<span class="hljs-string"><span class="hljs-string">"100%"</span></span>)
.justifyContent(FlexAlign.SpaceEvenly)
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
更多关于HarmonyOS 鸿蒙Next如何对某个组件进行截图?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
补充 【1】当设置占位隐藏.visibility(Visibility.Hidden)时,依然可以截图。 【2】如果是长截屏,可以放进Scroll中,参考:https://developer.huawei.com/consumer/cn/blog/topic/03157983727832042
楼主问题解决了吗?