如何将img的src设置为来自url的img。本机脚本

时间:2018-06-25 19:36:23

标签: nativescript

使用image-picker module我成功拍摄了一张图片,
网址:/storage/emulated/0/Screenshots/Screenshot_20180624-232124.png

现在我有了一个src,我尝试应用它。

//Url is the url above^
url = url.substring(0,url.length-4);//removes the .png or .jpg from url.
page.getViewById(`myImg`).src = `res:/${url}`;

不应用它。我刚得到错误:pasted at pastebin
图像不会改变。

我在做什么错?我已经查看了模块和NS文档上的文档。

2 个答案:

答案 0 :(得分:0)

通过将其设置为url,可以直接使用从image-picker模块获得的图像路径。

<Image src={{url}}></Image>url="/storage/emulated/0/Screenshots/Screenshot_20180624-232124.png"

答案 1 :(得分:0)

欢迎,我得到了别人的帮助。 通过添加:

const imageSourceModule = require(`tns-core-modules/image-source`);
let img = imageSourceModule.fromFile(url);
page.getViewById(`myImg`).imageSource = img;

我不知道imageSource属性,因为文档使用src

相关问题