我将画布图像保存在 sdcard 中。我将其保存到名为 Pictures 的文件夹中,并尝试将其显示回设备上。
现在我必须取回它并显示它。我尝试了以下代码:
Javascript
var ShowSavedImage = function(Imagename){
alert("in ShowSavedImage ");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, onFail);
}
function onFail(message) {
alert('Failed because: ' + message);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("Pictures/b64Image_1372901806166.png", {create: true}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file){
readDataUrl(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
document.getElementById("smallImage").style.display='block';
document.getElementById("smallImage").src = evt.target.result;
};
reader.readAsDataURL(file);
}
function fail(evt) {
console.log(evt.target.error.code);
}
HTML
<div data-role="page" id="SavedImage">
<div data-role="header" class= "header" data-position="fixed" data-tap-toggle="false" >
</div>
<div data-role="content" >
<center>
<h3 id="savedImageHeader"></h3>
<!-- <img src="" id="savedImageDisplay" style="display:none;height:auto; max-height:70%; width:auto; max-width:90%;"/> -->
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
</center>
</div>
</div>
当我尝试此代码时,出现以下错误
07-04 09:26:11.418: I/Web Console(22909): processMessage failed: Stack: TypeError: Cannot read property 'style' of null
07-04 09:26:11.418: I/Web Console(22909): at [object Object].<anonymous> (file:///android_asset/www/js/list.js:691:45)
07-04 09:26:11.418: I/Web Console(22909): at file:///android_asset/www/js/cordova-2.5.0.js:2549:20
07-04 09:26:11.418: I/Web Console(22909): at Object.captureReturnValue [as success] (file:///android_asset/www/js/cordova-2.5.0.js:847:20)
07-04 09:26:11.418: I/Web Console(22909): at Object.callbackFromNative (file:///android_asset/www/js/cordova-2.5.0.js:291:46)
07-04 09:26:11.418: I/Web Console(22909): at processMessage (file:///android_asset/www/js/cordova-2.5.0.js:964:21)
07-04 09:26:11.418: I/Web Console(22909): at Function.processMessages (file:///android_asset/www/js/cordova-2.5.0.js:1002:17)
07-04 09:26:11.418: I/Web Console(22909): at androidExec (file:///android_asset/www/js/cordova-2.5.0.js:856:21)
07-04 09:26:11.418: I/Web Console(22909): at [object Object].readAsDataURL (file:///android_asset/www/js/cordova-2.5.0.js:2528:5)
07-04 09:26:11.418: I/Web Console(22909): at readDataUrl (file:///android_asset/www/js/list.js:694:12)
07-04 09:26:11.418: I/Web Console(22909): at gotFile (file:///android_asset/www/js/list.js:683:5) at file:///android_asset/www/js/cordova-2.5.0.js:971
我是 PhoneGap 的新手,我不明白出了什么问题。
如何解决这个问题?