2016-12-29 29 views
2

我想使用圖庫中的照片然後裁剪。我正在使用this插件。它絕對沒有文檔,所以我需要一點幫助。點擊按鈕後,我想打開圖庫並選擇圖像,然後裁剪。我在我的功能myapp.js從圖庫中的Phonegap圖像選擇器不能正常工作

function uploadImage(){ 
    window.imagePicker.getPictures(
     function(results) { 
      for (var i = 0; i < results.length; i++) { 
       console.log('Image URI: ' + results[i]); 
      } 
     }, function (error) { 
      console.log('Error: ' + error); 
     }, { 
      maximumImagesCount: 10, 
      width: 800 
     } 
    ); 
} 

我打電話給它按鈕點擊。

<a href="#" onClick="uploadImage();">Upload</a> 

但我的應用程序崩潰。

不幸的是,應用程序已停止工作。

我該怎麼辦?

+0

嘗試在代碼中添加'try-catch'塊並檢查是否收到任何錯誤。還首先設置警報來檢查功能是否正常工作。 –

回答

3

你可以使用默認的PhoneGap插件相機獲得的圖像和裁剪。代碼低於此值,您可以從官方網站上的phongegap文檔輕鬆獲取該代碼。

function uploadImage(){ 
    navigator.camera.getPicture(onSuccess, onFail, { quality: 50, 
       sourceType: Camera.PictureSourceType.PHOTOLIBRARY, 
       allowEdit: true, 
       destinationType: Camera.DestinationType.FILE_URI 
       }); 
} 
function onSuccess(imageURI){ 
       var image = document.getElementById('smallimage'); 
       image.src = "data:image/jpeg;base64," +imageURI; 
      } 

      function onFail(message){ 
      } 

allowEdit選項將提供裁剪選項,您甚至可以通過以下選項給出固定的裁剪寬度和高度。

 targetWidth: 400,targetHeight: 250, 
+0

像一個魅力工作。 –