Cordova裁剪插件

g0czyy6m  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(158)

我目前正在一个android应用程序中尝试使用这个cordova plugin来裁剪上传后的图片。README说要这样使用它:

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)
}

知道为什么它不工作吗?提前非常感谢:)

bq9c1y66

bq9c1y661#

您getPicture代码在哪里?它们应该一起工作...尝试类似这样的代码..

// * 我假设您在安装了cordova-plugin-cameracordova-plugin crop之后调用了以下代码,因此现在在按钮上编写一个onClick事件,以调用函数中的以下代码行 *

navigator.camera.getPicture(onPhotoDataSuccess, onFail, { 
    correctOrientation: true, 
    targetWidth: 1024, 
    targetHeight: 1024, 
    destinationType: destinationType.FILE_URI 
});
  • //现在在onPhotoDataSuccess中获取图像url.. api从destinationType返回的url.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");
        });

}

相关问题