相机插件 - 无法裁剪图库图片

时间:2016-11-28 15:01:53

标签: cordova angular typescript ionic2 cordova-plugins

使用cordova-plugin-camera

我有一个移动应用程序,我希望用户拍照或从他们保存的相册中选择一个。

现在这两种功能都有效。问题出在保存的相册中。

为了防止压缩图像,我将allowEdit设置为true以基本上强制使用方形图片而不是矩形。使用相机拍摄照片时效果很好,但对保存的相册不起作用。

查看网格线 - 裁剪工具

是否有选项/解决方法来解决此问题?

(注意我在使用DATA_URL时知道常见的内存问题,但这是必需的)

 /** takeImage - changes the image of a participant to a file from the camera */
    changePicture(type: string) {
        // processing might take a while, set up loading message
        let loading = this.loadingCtrl.create({
            content: 'Processing...',
            spinner: 'crescent'
        });
        // set the phototype (make photo from camera or choose from gallery)
        let photoType = Camera.PictureSourceType.CAMERA;
        if(type === 'gallery') {
            photoType = Camera.PictureSourceType.SAVEDPHOTOALBUM;
        }
        // setting up the options
        Camera.getPicture({
            quality: 85,    // 85% to reduce size
            destinationType: Camera.DestinationType.DATA_URL, // returns a base64 string
            sourceType: photoType, // source type mentioned above
            allowEdit: true, // allows us to crop the picture (force square) <-- doesnt work on SAVEDPHOTOALBUM
            saveToPhotoAlbum: true, // saving the created photo to album (reusability)
            correctOrientation: true, // allow the user to rotate the image
            targetWidth: 200,
            targetHeight: 200
        }).then((imageData) => {
            loading.present();
            // change the image for every user
            this.apiCaller.changeImage(this.participant.id, imageData).subscribe(response => {
                // set the participant's base64image so it will be updated in the view
                this.participant.base64image = imageData;
                loading.dismiss();
            });
        }, err => {
            alert(err);
        });
    }

0 个答案:

没有答案