当从电话库中选择任何照片时,我写的以下代码总是返回空值。
<script type="text/javascript">
var imgData = null;
var pictureSource = null;
var destinationType = null;
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
function selectPhotoFromLibrary(e) {
if (e) e.preventDefault();
navigator.camera.getPicture(onSuccess, onFail,
{
sourceType: pictureSource.PHOTOLIBRARY,
destinationType: destinationType.DATA_URL
}
);
}
function selectPhotoFromAlbums(e) {
if (e) e.preventDefault();
navigator.camera.getPicture(onSuccess, onFail,
{
quality: 50,
sourceType: pictureSource.SAVEDPHOTOALBUM,
destinationType: destinationType.DATA_URL
}
);
}
function onSuccess(data) {
alert(data);
imgData = data;
}
function onFail(msg) {
navigator.notification.alert(msg, null, "Error", "OK");
}
</script>
HTML
<div id="buttons">
<input value="Select Photo From Library" style="margin: 5px; width: 95%;" onclick="selectPhotoFromLibrary(event)" type="button">
<br>
<input value="Select Photo From Albums" style="margin: 5px; width: 95%;" onclick="selectPhotoFromAlbums(event)" type="button">
</div>