如何使用科尔多瓦获取手机的所有图库图像?
How to fetch all gallery image of mobile using cordova?
我想获取移动设备的完整图库以在自定义网格中显示它们,这可能吗?现在我正在使用 $cordovaImagePicker
将我重定向到画廊,然后在选择图像后我得到了该图像的 Uri。相反,我想要自动选择完整的图库图像 uri。
Controller
$scope.getImageFromGallery = function() {
// Image picker will load images according to these settings
var options = {
maximumImagesCount: 1, // Max number of selected images, I'm using only one for this example
width: 800,
height: 800,
quality: 80 // Higher is better
};
$cordovaImagePicker.getPictures(options).then(function(results) {
// Loop through acquired images
for (var i = 0; i < results.length; i++) {
alert(results);
$scope.image = results[i];
// Print image URI
}
}, function(error) {
console.log('Error: ' + JSON.stringify(error)); // In case of error
});
}
检查此 link,可能对您有用。
http://www.digitalnoiz.com/mobile-development/photo-gallery-with-phonegap-and-jquery-mobile/
最简单的方法是使用cordova-gallery-api插件,参考下面的例子:
galleryAPI.getAlbums(function(items)
{
var html = "";
for(var i = 0; i < items.length; i++)
{
var album = items[i];
html += '<a href="javascript:loadAlbum(\'' + album.title + '\')" class="album"><span>' + escape(album.title) + '</span></a>';
}
$content.innerHTML = html;
}, function(error){alert(error);});
window.loadAlbum = function(albumName)
{
galleryAPI.getMedia(albumName, function(items)
{
var html = "";
for(var i = 0; i < items.length; i++)
{
var media = items[i];
html += '<a href="javascript:void()" class="media"><img src="file://' + media.thumbnail + '" /></a>';
}
$content.innerHTML = html;
}, function(error){alert(error);});
};
添加this插件,
cordova plugin add https://github.com/wymsee/cordova-imagePicker.git
控制器
$scope.images = [];
$scope.selectImages = function() {
$cordovaImagePicker.getPictures(
function(results) {
for (var i = 0; i < results.length; i++) {
$scope.images.push(results[i]);
}
if (!$scope.$$phase) {
$scope.$apply();
}
},
function(error) {
console.log('Error: ' + error);
}
);
};
Html
<div class="row responsive-md">
<div class="col col-25" ng-repeat="image in images">
<img ng-src="{{image.src}}" width="100%" />
</div>
</div>
我想获取移动设备的完整图库以在自定义网格中显示它们,这可能吗?现在我正在使用 $cordovaImagePicker
将我重定向到画廊,然后在选择图像后我得到了该图像的 Uri。相反,我想要自动选择完整的图库图像 uri。
Controller
$scope.getImageFromGallery = function() {
// Image picker will load images according to these settings
var options = {
maximumImagesCount: 1, // Max number of selected images, I'm using only one for this example
width: 800,
height: 800,
quality: 80 // Higher is better
};
$cordovaImagePicker.getPictures(options).then(function(results) {
// Loop through acquired images
for (var i = 0; i < results.length; i++) {
alert(results);
$scope.image = results[i];
// Print image URI
}
}, function(error) {
console.log('Error: ' + JSON.stringify(error)); // In case of error
});
}
检查此 link,可能对您有用。
http://www.digitalnoiz.com/mobile-development/photo-gallery-with-phonegap-and-jquery-mobile/
最简单的方法是使用cordova-gallery-api插件,参考下面的例子:
galleryAPI.getAlbums(function(items)
{
var html = "";
for(var i = 0; i < items.length; i++)
{
var album = items[i];
html += '<a href="javascript:loadAlbum(\'' + album.title + '\')" class="album"><span>' + escape(album.title) + '</span></a>';
}
$content.innerHTML = html;
}, function(error){alert(error);});
window.loadAlbum = function(albumName)
{
galleryAPI.getMedia(albumName, function(items)
{
var html = "";
for(var i = 0; i < items.length; i++)
{
var media = items[i];
html += '<a href="javascript:void()" class="media"><img src="file://' + media.thumbnail + '" /></a>';
}
$content.innerHTML = html;
}, function(error){alert(error);});
};
添加this插件,
cordova plugin add https://github.com/wymsee/cordova-imagePicker.git
控制器
$scope.images = [];
$scope.selectImages = function() {
$cordovaImagePicker.getPictures(
function(results) {
for (var i = 0; i < results.length; i++) {
$scope.images.push(results[i]);
}
if (!$scope.$$phase) {
$scope.$apply();
}
},
function(error) {
console.log('Error: ' + error);
}
);
};
Html
<div class="row responsive-md">
<div class="col col-25" ng-repeat="image in images">
<img ng-src="{{image.src}}" width="100%" />
</div>
</div>