我正在尝试将 base64 图像保存到本地存储或WebSQL中,但它只显示图像并在显示“保存到本地存储”消息后停留在那里。
代码: -
<div id="photoImage"></div>
<a href="#" class="btn btn-primary" onclick="capturePhoto()" style="margin-bottom: 5px">Capture</a>
<script>
function capturePhoto(){
navigator.camera.getPicture(onSuccess, onFail, {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL
});
}
function onSuccess(imageData){
var image = document.getElementById("photoImage");
image.src = "data:image/jpeg;base64," + imageData;
alert("Save Into Local Storage");
//Save into local storage
localStorage.setItem("imageData", "data:image/jpeg;base64," + imageData);
alert("DONE");
}
function onFail(e) {
alert('Failed because: ' + e);
}
</script>
插件: -
<plugin name="cordova-plugin-camera" spec="1.2.0" source="pgb" />
答案 0 :(得分:0)
更改onSuccess上的功能
function onSuccess(imageData){
var image = document.getElementById("photoImage");
image.src = "data:image/jpeg;base64," + imageData;
alert("Save Into Local Storage");
//Save into local storage
localStorage.setItem("imageData", imageData);
alert("DONE");
}
希望它会对你有所帮助。