簡體   English   中英

科爾多瓦作物插件

[英]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-cameracordova-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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM