如何从本地存储中获取图像,然后在本机脚本中将其显示在屏幕上.我正在使用nativescript-imagepicker和fs [英] How can I get images from local storage and then display them on screen in Native Script. I am using nativescript-imagepicker and fs

查看:66
本文介绍了如何从本地存储中获取图像,然后在本机脚本中将其显示在屏幕上.我正在使用nativescript-imagepicker和fs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Native Script的新手.如何显示本地存储中的图像?我使用了nativescript-imagepicker,但是随后,我不知道图像的存储位置.我正在使用此代码.

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);
    });
}

我正在尝试将路径设置为SlcImg.在应用程序的xml部分中,这是代码.

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>

推荐答案

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);
    });

使用fileUri.而且setTimeout是可选的,在我没有这个项目的项目中,应用程序屏幕空白一秒钟.

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

这篇关于如何从本地存储中获取图像,然后在本机脚本中将其显示在屏幕上.我正在使用nativescript-imagepicker和fs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆