如何使用 Nativescript 从 android 个图库中选择图片?
How can I choose picture from android gallery using Nativescript?
我一直在浏览 Nativescript 网站,但未能找到从我的 phone 本地获取图片的方法。如果有人知道在 android 和 ios 上执行此操作的方法,我将非常高兴。
在您的情况下,您可以使用 file-system
module and native code to access the external storage from your device. you can get the path to the file and open it with the NativeScript file-system
api. I am attaching sample example how you could get the path os an image from the Camera Roll storage. You could also review the article here,其中描述了您可以从 android 设备存储访问的内容。
打字稿
import {path} from "file-system";
var tempPicturePath = path.join(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath(), "20160719_155053.jpg");
console.log("extr storage "+tempPicturePath);
javascript
var file_system_1 = require("file-system");
var tempPicturePath = file_system_1.path.join(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath(), "20160719_155053.jpg");
console.log("extr storage " + tempPicturePath);
尼克,我想你想让用户从图库中选择图片,对吧?我用这个 nativescript 插件完成了这个:
https://www.npmjs.com/package/nativescript-imagepicker
import * as imagepicker from "nativescript-imagepicker";
let context = imagepicker.create({
mode: "single" // use "multiple" for multiple selection
});
context
.authorize()
.then(function() {
return context.present();
})
.then(function(selection) {
selection.forEach(function(selected) {
// process the selected image
});
list.items = selection;
}).catch(function (e) {
// process error
});
根据 https://whatwebcando.today/camera-microphone.html,您可以只使用普通的 HTML- 输入字段。
<input type="file" accept="image/*">
按下移动设备上的按钮可打开图库,其中包含实时相机图片选项和文件浏览器 (Anroid (Mi9T) behaviour)。
希望这个回答没有漏掉您的意思;-)
我一直在浏览 Nativescript 网站,但未能找到从我的 phone 本地获取图片的方法。如果有人知道在 android 和 ios 上执行此操作的方法,我将非常高兴。
在您的情况下,您可以使用 file-system
module and native code to access the external storage from your device. you can get the path to the file and open it with the NativeScript file-system
api. I am attaching sample example how you could get the path os an image from the Camera Roll storage. You could also review the article here,其中描述了您可以从 android 设备存储访问的内容。
打字稿
import {path} from "file-system";
var tempPicturePath = path.join(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath(), "20160719_155053.jpg");
console.log("extr storage "+tempPicturePath);
javascript
var file_system_1 = require("file-system");
var tempPicturePath = file_system_1.path.join(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath(), "20160719_155053.jpg");
console.log("extr storage " + tempPicturePath);
尼克,我想你想让用户从图库中选择图片,对吧?我用这个 nativescript 插件完成了这个:
https://www.npmjs.com/package/nativescript-imagepicker
import * as imagepicker from "nativescript-imagepicker";
let context = imagepicker.create({
mode: "single" // use "multiple" for multiple selection
});
context
.authorize()
.then(function() {
return context.present();
})
.then(function(selection) {
selection.forEach(function(selected) {
// process the selected image
});
list.items = selection;
}).catch(function (e) {
// process error
});
根据 https://whatwebcando.today/camera-microphone.html,您可以只使用普通的 HTML- 输入字段。
<input type="file" accept="image/*">
按下移动设备上的按钮可打开图库,其中包含实时相机图片选项和文件浏览器 (Anroid (Mi9T) behaviour)。
希望这个回答没有漏掉您的意思;-)