相机插件不适用于离子

时间:2016-11-21 08:14:55

标签: javascript android angularjs ionic-framework

我想使用相机插件和离子文件上传来拍照。但是,当我单击按钮时,它不起作用。我看着控制台,没有错误。

查看:

int catalogsNumber(int c)
{
    int i, n = 0;

    for (i = 0; i < c; i++) {
        n = (n + 1) * (i + 1);
    }

    return n;
}

// Results in С++
catalogsNumber ( 3 ) => 15              // correct
catalogsNumber ( 4 ) => 64              // correct
catalogsNumber ( 5 ) => 325             // correct
catalogsNumber ( 12 ) => 1302061344     // correct
catalogsNumber ( 13 ) => -253071699     // ¯\_(ツ)_/¯
catalogsNumber ( 14 ) => 751963524      // ¯\_(ツ)_/¯

app:

<button class="button button-full button-assertive" ng-click="takePhoto">Take Photo</button>
<button class="button button-full button-assertive" ng-click="choosePhoto">Choose Photo</button>
<img ng-src="{{user.picture}}">

感谢所有帮助。 我是新手。

3 个答案:

答案 0 :(得分:1)

使用以下简单控制器查看它是否有效。也别忘了安装Cordovacamera插件。我没有看到你的代码使用任何cordova插件

app.controller('MainCtrl', function($scope, $cordovaCamera) {
 $scope.takeImage = function() {
        var options = {
            quality: 80,
            destinationType: Camera.DestinationType.DATA_URL,
            sourceType: Camera.PictureSourceType.CAMERA,
            allowEdit: true,
            encodingType: Camera.EncodingType.JPEG,
            targetWidth: 250,
            targetHeight: 250,
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: false
        };

        $cordovaCamera.getPicture(options).then(function(imageData) {
            $scope.srcImage = "data:image/jpeg;base64," + imageData;
        }, function(err) {
            // error
        });
    }
});

将以下代码用于index.html

<ion-content ng-controller="MainCtrl">
        <img ng-src="{{srcImage || 'img/dummy.jpg'}}" id="srcImage" width="250 " 
             height="250" style="display: block; margin: 0 auto;"/><br/>
        <button class="button button-full button-positive " ng-click="takeImage() ">Take Image</button><br/>
    </ion-content>

答案 1 :(得分:0)

首先使用以下命令

安装Camera插件
 cordova plugin add cordova-plugin-camera

然后,尝试实现以下代码从相机拍照,

HTML文件,

 <ion-content>
    <button class="button button-full button-assertive" ng-click="takePhoto">Take Photo</button>
    <img ng-src="{{ImagePath}}" style="width:250px;height:250x;"/><br/>
 <ion-content>

<强>控制器:

app.controller('MainCtrl', function($scope){
    $scope.takePhoto = function() {
       navigator.camera.getPicture(function(imageURI)
       {
          $scope.ImagePath = imageURI;
       }, function(err) {
          // Ruh-roh, something bad happened
       },{quality: 50,
          destinationType: Camera.DestinationType.FILE_URI,
          encodingType: Camera.EncodingType.JPEG,
          targetWidth: 300,
          targetHeight: 300
       });
    }
})

希望这会帮助你!!!!

答案 2 :(得分:0)

您没有在工厂使用$ cordovaCamera,也没有使用所有imageOptions,请参阅ngCordova Camera Plugin的官方文档。 Here

<button class="button button-full button-assertive" ng-click="takePictures">Take Photo</button>

请使用正确的ng-click功能与控制器绑定。