使用Phonegap获取ImageURI时出错

时间:2013-12-07 13:14:52

标签: android angularjs cordova image-gallery

我正在尝试使用phonegap 3.0.0(+ angular)从用户的相机或图库中获取照片

出于某种原因,它仅适用于相机拍摄的照片

这是我的HTML:

<button ng-click="getPhoto(0);">0</button><br>
<button ng-click="getPhoto(1);">1</button><br>
<button ng-click="getPhoto(2);">2</button><br>
<img ng-src="{{preview}}" />

getPhoto的参数是phonegap的PictureSourceType

Camera.PictureSourceType = {
    PHOTOLIBRARY : 0,
    CAMERA : 1,
    SAVEDPHOTOALBUM : 2
};

Javascript(Angular的控件)中的代码是

$scope.preview="";
$scope.getPhoto= function(source) {
    navigator.camera.getPicture(function(imageURI)
                                {
                                    $scope.preview=imageURI;
                                },function(message) {
                                    alert('Failed because: ' + message);
                                },
                                {
                                    quality: 50,
                                    destinationType: 1,
                                    sourceType: source
                                });
}

1 个答案:

答案 0 :(得分:-1)

从PHOTOLIBRARY获取照片

  navigator.camera.getPicture(function(imageURI)                                {
                                $scope.preview=imageURI;
                        }, function(message) {
                                alert('Failed because: ' + message);
                        }, { quality: 50,destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY});