gpt4 book ai didi

android - ionic / Cordova : Upload image from phone's gallery

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:01:14 26 4
gpt4 key购买 nike

我希望用户能够拍照或从手机图库中选择图片。

我成功地拍照并获得了 imageURI

我使用 Genymotion 作为模拟器,因为我需要访问一些功能,例如相机。我知道还有其他一些解决方案。模拟时调试起来有点困难,但这是我目前发现的访问相机的唯一方法。因此我看不到第二部分发生了什么(从图库中选择图像)。

$scope.uploadPopup = function() {
var uploadPopup = $ionicPopup.show({
title: "Edit profile's picture",
templateUrl: 'templates/partials/upload-img.html',
buttons: [
{
text: '',
type: 'button-energized icon-center ion-ios7-camera',
onTap: function(e) {

// e.preventDefault() will stop the popup from closing when tapped.
e.preventDefault();
alert('Getting camera');
Camera.getPicture({
quality: 100,
saveToPhotoAlbum: false
}).then(function(imageURI) {
alert(imageURI);
$scope.lastPhoto = imageURI;
}, function(err) {
alert(err);
});

}
},
{
text: 'From gallery',
type: 'button',
onTap: function(e) {
e.preventDefault();
alert('Getting gallery');
Camera.getPicture({
quality: 100,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY
}).then(function(imageURI) {
alert(imageURI);
$scope.lastPhoto = imageURI;
}, function(err) {
alert(err);
});
}
}
]
});
};

服务:

app.factory('Camera', ['$q', function($q) {

return {
getPicture: function(options) {
var q = $q.defer();

navigator.camera.getPicture(function(result) {
// Do any magic you need
q.resolve(result);
}, function(err) {
q.reject(err);
}, options);

return q.promise;
}
}

}]);

这是正确的做法吗?有什么提示或想法吗?

更新:

当我添加时:

sourceType: Camera.PictureSourceType.CAMERA

到第一个功能(从相机拍照)。它不起作用了。虽然没有(可能使用默认的)它确实有效。

最佳答案

当我添加 sourceType 而不是使用默认 sourceType(CAMERA) 时

sourceType: Camera.PictureSourceType.CAMERA

它不再工作了,所以我猜这里出了点问题。

正确的语法是:

navigator.camera.PictureSourceType.CAMERA

或(有不同的选项):

navigator.camera.PictureSourceType.PHOTOLIBRARY

不确定为什么是“navigator.camera”而不是“Camera”,我猜“Camera”是“navigator.camera”的别名。

关于android - ionic / Cordova : Upload image from phone's gallery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30080003/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com