在图片中拍摄的照片没有显示在android中的cordova相机插件中裁剪

时间:2016-10-19 04:47:37

标签: javascript cordova ionic-framework

使用camera cordova plugin在裁剪选项中不显示从照片中拍摄的照片。但是,当我从图库中选择图像或从相机拍摄照片时,会出现裁剪选项。

插件

cordova-plugin-camera 2.1.1

 var options = {
            quality: 75,
            destinationType: Camera.DestinationType.DATA_URL,
            sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
            allowEdit: true,
            encodingType: Camera.EncodingType.JPEG,
            targetWidth: 300,
            targetHeight: 300,
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: false
        };
        $cordovaCamera.getPicture(options).then(function(imageData) {
        console.log('succes')
        }, function(err) {
        console.log('succes')
        });

我真的需要一些帮助来解决这个问题。

1 个答案:

答案 0 :(得分:2)

您可以参考ngCordove - Camera

你需要依赖注入  添加“ngCordova”,就像这样。

<强> app.js

angular.module('starter', ['ionic','ngCordova'])

<强> camera.html

<ion-content>
    <div class="list">

        <div class="item item-thumbnail-right item-icon-right" ng-click="toCamera()">
            <img id="myImage" style="margin-right:50px;">
            <h2 class="positive">Camera</h2>
            <i class="icon ion-ios-arrow-right balanced"></i>
        </div>

    </div>
</ion-content>

<强> controllers.js

app.controller('CameraCtrl', function ($scope, $cordovaCamera) {

$scope.toCamera = function () {
    var hideSheet = $ionicActionSheet.show({
        buttons: [
            { text: 'Take a picture' },
            { text: 'Select a picture' }
        ],
        cancelText: 'Cancel',
        cancel: function () {
        },
        buttonClicked: function (index) {
            console.log(index);
            if (index == '0') {
                document.addEventListener("deviceready", function () {
                    //take a picture
                    var options = {
                        quality: 100,
                        destinationType: Camera.DestinationType.DATA_URL,
                        sourceType: Camera.PictureSourceType.CAMERA,
                        allowEdit: true,
                        encodingType: Camera.EncodingType.JPEG,
                        targetWidth: 1280,
                        targetHeight: 720,
                        popoverOptions: CameraPopoverOptions,
                        saveToPhotoAlbum: true,
                        correctOrientation: true
                    };
                    $cordovaCamera.getPicture(options).then(function (imageData) {
                        var image = document.getElementById('myImage');
                        image.src = "data:image/jpeg;base64," + imageData;
                    }, function (err) {
                        // error
                    });
                }, false);

            } else if (index == '1') {
                document.addEventListener("deviceready", function () {
                    //Select a picture
                    var options = {
                        destinationType: Camera.DestinationType.FILE_URI,
                        sourceType: 2,     //set 0 or 2,is system picture
                        quality: 100,
                        allowEdit: true,
                        targetWidth: 1280,
                        targetHeight: 720
                    };

                    $cordovaCamera.getPicture(options).then(function (imageURI) {
                        var image = document.getElementById('myImage');
                        image.src = imageURI;
                    }, function (err) {
                        // error
                    });

                    //$cordovaCamera.cleanup().then(); // only for FILE_URI

                }, false);
            }
            return true;
        }
    })
}});