[英]Phonegap image picker from gallery not working properly
我想使用圖庫中的照片,然后進行裁剪。 我正在使用這個插件。 它絕對沒有文檔,所以我需要一些幫助。 單擊按鈕時,我要打開圖庫並選擇圖像,然后也將其裁剪。 我在myapp.js
做了一個函數
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>
但是我的應用崩潰了。
不幸的是,App已停止工作。
我該怎么辦?
您可以使用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,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.