裁剪404

时间:2017-03-16 11:12:06

标签: cordova angular ionic2 cordova-plugins crop

我正在使用Ionic 2和cordova-plugin-crop裁剪图像。

如果我拍照pictureSourceType === navigator.camera.PictureSourceType.CAMERA),裁剪效果正常,但如果我从文件夹中挑选图片pictureSourceType === navigator.camera.PictureSourceType.SAVEDPHOTOALBUM ),并尝试裁剪它,我得到:

  裁剪404时出现

错误

这是我的代码:

takeThePhoto(pictureSourceType: any) {
    let options = {
        sourceType: pictureSourceType,
        destinationType: Camera.DestinationType.FILE_URI,
        quality: 50,
        targetWidth: 720,
        correctOrientation: true,
        encodingType: Camera.EncodingType.JPEG
    }
    if (pictureSourceType === navigator.camera.PictureSourceType.SAVEDPHOTOALBUM) {
        options.correctOrientation = false;
    }
    Camera.getPicture(options).then((imageURI) => {
        window['plugins'].crop.promise(imageURI, {
            quality: 75
        }).then(newPath => {
            alert('newPath = ' + newPath);
            return this.toBase64(newPath).then((base64Img) => {
                this.base64Image = base64Img;
            }).catch((error) => {
                console.error("ERROR -> " + JSON.stringify(error));
                alert("ERROR: " + JSON.stringify(error));
            });
        },
            error => {
                console.error("CROP ERROR -> " + JSON.stringify(error));
                alert("CROP ERROR: " + JSON.stringify(error));
            }
            ).catch((error) => {
                console.error("ERROR imageURI -> " + JSON.stringify(error));
                alert("ERROR imageURI: " + JSON.stringify(error));
            });
    },
        error => {
            // console.error("CAMERA ERROR -> " + JSON.stringify(error));
            // alert("CAMERA ERROR: " + JSON.stringify(error));
        }
    ).catch((error) => {
        console.error("ERROR getPicture -> " + JSON.stringify(error));
        alert("ERROR getPicture: " + JSON.stringify(error));
    });
}

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

正如您已经从'ionic-native'导入'Camera',请尝试替换:

  navigator.camera.PictureSourceType.SAVEDPHOTOALBUM

Camera.PictureSourceType.SAVEDPHOTOALBUM

并且,尝试替换

window['plugins'].crop

import { Crop } from 'ionic-native';
Crop.crop(.... )

插件的github中有ionic2用法示例,如果有帮助: https://github.com/jeduan/cordova-plugin-crop