【发布时间】:2014-01-06 10:27:34
【问题描述】:
我正在尝试从 sdcard 中读取不是由手机摄像头拍摄的图像,并让图像 src 显示在我的应用程序上。我为此尝试了许多解决方案并获得了许多更新。但它仍然无法正常工作。这是我的代码:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess);
}
function onFileSystemSuccess(fileSystem){
fileSystem.root.getFile("test.jpg", {create: false, exclusive: false}, fileSuccess);
}
function fileSuccess(fileEntry){
fileEntry.file(gotfile);
}
function gotFile(file){
readDataUrl(file);
}
function readDataUrl(file){
var reader = new FileReader();
reader.onlaodend=function(evt){
console.log(evt.target.result);
document.getElementById("img_test").src=evt.target.result;
};
reader.readAsDataURL(file);
}
我正在尝试获取这个 img 的 src:
<div>
<img id="img_test" src="">
</div>
文件路径有什么问题吗?我是phonegap的新手。请让我知道我在这里做错了什么。谢谢...:)
【问题讨论】:
标签: javascript cordova