裁剪 404 时出现 cordova-plugin-crop 错误
cordova-plugin-crop error on cropping 404
我正在使用 Ionic 2 和 cordova-plugin-crop 裁剪图像。
如果我拍照 (pictureSourceType === navigator.camera.PictureSourceType.CAMERA
),裁剪效果很好,但如果我从文件夹中选择一张图片 (pictureSourceType === navigator.camera.PictureSourceType.SAVEDPHOTOALBUM
),并尝试裁剪它,我得到:
error on cropping 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));
});
}
感谢任何帮助。
因为您已经从 '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
我正在使用 Ionic 2 和 cordova-plugin-crop 裁剪图像。
如果我拍照 (pictureSourceType === navigator.camera.PictureSourceType.CAMERA
),裁剪效果很好,但如果我从文件夹中选择一张图片 (pictureSourceType === navigator.camera.PictureSourceType.SAVEDPHOTOALBUM
),并尝试裁剪它,我得到:
error on cropping 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));
});
}
感谢任何帮助。
因为您已经从 '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