1、onTouch方法会获得TouchEvent对象,其中包含EventTarget:触发事件的元素对象显示区域 Area,参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-events-touch-V5\#ontouch.onTouch((event?: TouchEvent) => { if(event?.target){ let height = event.target.area.height; } })2、image控件加载图片资源可以参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-graphics-display-V5\#加载图片资源Image组件不能直接传入应用沙箱路径,需要传入应用沙箱uri。Image的src支持file://路径前缀的字符串,应用沙箱URI:file://<bundleName\>/<sandboxPath\>。用于读取本应用安装目录下files文件夹下的图片资源。需要保证目录包路径下的文件有可读权限。参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-image-V5\#image-1通过调用@ohos.file.fileuri模块的fileuri.getUriFromPath将沙箱路径转化为沙箱uri,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-file-fileuri-V5\#fileurigeturifrompath
1、onTouch方法会获得TouchEvent对象,其中包含EventTarget:触发事件的元素对象显示区域 Area,参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-events-touch-V5\#ontouch
2、image控件加载图片资源可以参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-graphics-display-V5\#加载图片资源
Image组件不能直接传入应用沙箱路径,需要传入应用沙箱uri。Image的src支持file://路径前缀的字符串,应用沙箱URI:file://<bundleName\>/<sandboxPath\>。用于读取本应用安装目录下files文件夹下的图片资源。需要保证目录包路径下的文件有可读权限。参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-image-V5\#image-1
通过调用@ohos.file.fileuri模块的fileuri.getUriFromPath将沙箱路径转化为沙箱uri,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-file-fileuri-V5\#fileurigeturifrompath