图库中的 Phonegap 图像选择器无法正常工作
Phonegap image picker from gallery not working properly
我想使用图库中的照片,然后对其进行裁剪。我正在使用 this 插件。它绝对没有文档,所以我需要一些帮助。单击按钮时,我想打开图库和 select 图像,然后也将其裁剪。我在 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>
但是我的应用程序崩溃了。
Unfortunately, App has stopped working.
我该怎么办?
您可以使用 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,
我想使用图库中的照片,然后对其进行裁剪。我正在使用 this 插件。它绝对没有文档,所以我需要一些帮助。单击按钮时,我想打开图库和 select 图像,然后也将其裁剪。我在 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>
但是我的应用程序崩溃了。
Unfortunately, App has stopped working.
我该怎么办?
您可以使用 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,