[英]Cordova Crop Plugin
我目前正在尝试在 android 应用程序中使用这个cordova 插件在上传图像后裁剪图像。 自述文件说要像这样使用它:
plugins.crop(function success () {
}, function fail () {
}, '/path/to/image', options)
不幸的是,我在 JavaScript 方面没有太多经验,所以我就这样厌倦了它:
handleCropPress: function () {
var oImage = this.byId("image");
var srcImage = oImage.getSrc();
plugins.crop(function success () {
}, function fail () {
}, srcImage)
}
任何想法为什么它不起作用? 提前谢谢了 :)
你的 getPicture 代码在哪里? 他们都应该携手合作......尝试这样的事情......
//我假设你在安装了cordova-plugin-camera
和cordova-plugin crop
之后已经调用了以下代码,所以现在在按钮上编写一个 onClick 事件来调用函数中的以下行
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
correctOrientation: true,
targetWidth: 1024,
targetHeight: 1024,
destinationType: destinationType.FILE_URI
});
// 现在在 onPhotoDataSuccess 中获取图像 url.. api 从destinationType.FILE_URI 返回的那个
function onPhotoDataSuccess(imageData) {
plugins.crop.promise(imageData)
.then(function success(imageFinal) {
// Success.
alert(imageFinal); //alert to see if you are getting the path
var picPreviewBox = document.getElementById('picPreviewBox'); //create an img tag with src="" and assign an ID named picPreviewBox or anything you feel like and call that id in the above line
picPreviewBox.style.display = 'block';
// //picPreviewBox.src = "data:image/jpeg;base64," + image;
picPreviewBox.src = imageFinal;
//$("#picPreviewBox").html('<img src="data:image/jpeg;base64,'+image+'" width="100%"/>');
})
.catch(function fail(err) {
// fail
$.alert("Seems your phone resources are too low to proceed further");
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.