如何使用图片库中的Ionic / angularjs进行访问?我只是想按每次按钮打开图库。怎么可能?
答案 0 :(得分:6)
您可以使用cordova相机插件
cordova插件添加org.apache.cordova.camera
插件参考: https://github.com/apache/cordova-plugin-camera
示例代码
$scope.getPhoto = function() {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
mediaType: Camera.MediaType.ALLMEDIA,
saveToPhotoAlbum: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
console.log("img URI= " + imageData);
//Here you will be getting image data
}, function(err) {
alert("Failed because: " + err);
console.log('Failed because: ' + err);
});
};
您只需将 sourceType 选项设置为 Camera.PictureSourceType.SAVEDPHOTOALBUM
答案 1 :(得分:2)
您可以使用以下链接获取ImagePicker的cordova插件:
http://ngcordova.com/docs/plugins/imagePicker/
示例:
$scope.OpenGallery = function() {
var options = {
maximumImagesCount: 1,
width: 350,
height: 500,
quality: 50
};
$cordovaImagePicker.getPictures(options).then(function (results) {
console.log(results);
},function(error) {
console.log(error);
});
}
答案 2 :(得分:0)
Ionic的家伙做了这个例子:https://github.com/driftyco/ionic-example-cordova-camera/blob/master/plugins/org.apache.cordova.camera/doc/index.md
作为第二种选择,您可以尝试使用imagePicker插件。
示例:
module.controller('ThisCtrl', function($scope, $cordovaImagePicker) {
var options = {
maximumImagesCount: 10,
width: 800,
height: 800,
quality: 80
};
$cordovaImagePicker.getPictures(options)
.then(function (results) {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
}
}, function(error) {
// error getting photos
});
});