How can I get images from local storage and then display them on screen in Native Script. I am using nativescript-imagepicker and fs

做~自己de王妃 提交于 2019-12-11 17:18:54

问题


I am new to Native Script. How can I display an image from local storage? I used the nativescript-imagepicker but then, I don't know where the image is stored. I am using this code.

var imagepicker = require("nativescript-imagepicker");

var context = imagepicker.create({ mode: "single" }); // use "multiple" for multiple selection

let SlcImg = ""; 

exports.imgPic = function() {
    context
    .authorize()
    .then(function() {
        return context.present();
    })
    .then(function(selection) {
        selection.forEach(function(selected) {
                SlcImg = path;
        })
    }).catch(function (e) {
        console.log(e);
    });
}

I am trying to set the path to SlcImg. In my xml part of the app this is the code.

<Image src="{{imageSource}}" class="imageCss" stretch="aspectFill"></Image>

回答1:


var context = imagepickerModule.create({
    mode: "single" // allow choosing single image
});
context
    .authorize()
    .then(function () {
        return context.present();
    })
    .then(function (selection) {
        console.log("Selection done:");
        setTimeout(() => {
            selection.forEach(function (selected) {
                selected.getImage().then((source) => {
                    console.log(selected.fileUri); // this is the uri you need
                });     
            });
        }, 1000);            
    }).catch(function (e) {
        console.log(e);
    });

Use the fileUri. And that setTimeout is optional, in my project without that, the app screen was going blank for a second.



来源:https://stackoverflow.com/questions/46817722/how-can-i-get-images-from-local-storage-and-then-display-them-on-screen-in-nativ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!