cordova相机插件相机插件不显示裁剪选项时,从画廊选择图像

elcex8rz  于 2022-11-15  发布在  其他
关注(0)|答案(3)|浏览(151)

我正在使用Cordova camera plugin。当我通过相机拍照时,它显示裁剪选项。但当我从图库中选择图像时,它不提供裁剪选项。当我从图库中选择图像时,有人能帮助我在相同的情况下有裁剪选项吗

var options = {
      quality: 100,
      allowEdit : 1,
      targetWidth: 800,
      targetHeight: 800,
      destinationType: Camera.DestinationType.FILE_URI,
      sourceType: sourceType,
      encodingType: 0,
      saveToPhotoAlbum: false
    };
ukdjmx9f

ukdjmx9f1#

对于裁剪的图像从画廊在Cordova camera plugin没有支持。为此,你必须合并Cordova camera plugincordova-plugin-crop尝试这个代码,而不是你的代码。

navigator.camera.getPicture(gotPhotoLibrary, onError, {
 quality: 50,
 destinationType: navigator.camera.DestinationType.FILE_URI,
 sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
 allowEdit: true,
 targetWidth: 200, //what widht you want after capaturing
 targetHeight: 200
 });
return true;


 function gotPhotoLibrary(imageUri) {
                    var options = {
                        quality: 150,
                        widthRatio: 1,
                        heightRatio: 1,
                        targetWidth: 600,
                        targetHeight: 600
                    };
plugins.crop.promise(imageUri, options)
  .then(function success(newPath) {
    window.resolveLocalFileSystemURI(newPath, function (fileEntry) {
                            fileEntry.file(function (fileObj) {
                               // your code here
                            });
                        });
                    });
                }

 function onError(err) {
     alertPopup = $ionicPopup.alert({
         title: '',
         template: err
                });
    }
yb3bgrhw

yb3bgrhw2#

为了允许crop选项,你必须在allowEdit中输入true,因为它是一个布尔值。但是正如我们的朋友在上面所说的,如果你使用插件cordova-plugin-crop会更好,因为allowEdit在某些设备上会失败

cgvd09ve

cgvd09ve3#

这是我认为很容易理解的代码

function clickFirstProfilePhoto(){
                
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, 
    {correctOrientation:true, 
    targetWidth:1024, 
    targetHeight: 1024, 
    destinationType: destinationType.FILE_URI
    });  
    
    //alowEdit is false by default if you don't mention  
    
    }
        
        function onPhotoDataSuccess(imageData) {
                   
        plugins.crop.promise(imageData).then(function success (imageFinal) {
                  // Success.
                  //alert(imageFinal);
                  var fileURI = imageFinal.substr(imageFinal.lastIndexOf('?') + 1);
                  //alert(fileURI);
                  resolveLocalFileSystemURL(imageFinal, function(entry) {
                    
                   
        
                    $("#picPreviewBox").html('<img src="'+entry.toInternalURL()+'" width="100%" />');
        
 //write a code to upload the picture to the server (I am currently stuck here btw)
        
                    
                  });
        
        
        }).catch(function fail (err) {
                  // fail
         $.alert("Seems your phone resources are too low to proceed further");
                });
        
         }
        
        
        
            function onFail(message) {
                navigator.notification.alert('Failed because ' + message);
                //$.alert("Sorry! something went wrong. Please restart this app and try again. In case if you still face any problem please report the bug on hithere@thetransme.in");
              }

相关问题