2017-02-23 44 views

回答

0

下面是一些代码,我在一个角1 /科尔多瓦(PhoneGap的)应用程序使用,显然,你可能要剥离出的承诺,它也不会以任何方式重构(只有两个复制/粘贴作业)但做的治疗。您还需要安装cordova文件插件。

function _launchEditor(imageUrl, options) { 
    /* 2.a) Prep work for calling `.edit()` */ 
    var deferred = $q.defer(); 

    function success(newUrl) { 
     /** 
     * This function will handle the conversion from a file to base64 format 
     * 
     * @path string 
     * @callback function receives as first parameter the content of the image 
     */ 
     function getFileContentAsBase64(path, callback) { 
     window.resolveLocalFileSystemURL(path, gotFile, error); 

     function gotFile(fileEntry) { 
      fileEntry.file(function (file) { 
      var reader = new FileReader(); 
      reader.onloadend = function (e) { 
       var content = this.result; 
       callback(content); 
      }; 
      // The most important point, use the readAsDatURL Method from the file plugin 
      reader.readAsDataURL(file); 
      }); 
     } 
     } 

     getFileContentAsBase64(newUrl, function (base64Image) { 
     //window.open(base64Image); 
     // Then you'll be able to handle the myimage.png file as base64 
     deferred.resolve({ 
      data: base64Image, 
      url: newUrl 
     }) 
     }); 
    } 

    function error(error) { 
     deferred.reject(error); 
    } 

    if (!options) { 
     options = { 
     outputType: CSDKImageEditor.OutputType.JPEG, 
     tools: [ 
      CSDKImageEditor.ToolType.CROP, 
      CSDKImageEditor.ToolType.ORIENTATION, 
      CSDKImageEditor.ToolType.TEXT, 
      CSDKImageEditor.ToolType.DRAW 
     ], 
     quality: 50 
     } 
    } 

    /* 2.b) Launch the Image Editor */ 
    CSDKImageEditor.edit(success, error, imageUrl, options); 
    return deferred.promise; 
    } 

然后只需用

_launchEditor(<ImageUrl>) 
     .then(function(data){ 
     //data.url = creativesdk saved image url 
     //data.data = base64 image data 
     }) 
调用