[英]Showing an image from LocalStore in HTML on PhoneGap/Cordovia on Windows Phone 7
在Windows Phone 7上運行的PhoneGap上以HTML標記顯示LocalStorage中的圖像需要什么?
從Internet下載圖像並將其存儲在手機上(在Windows Phone 7上,圖像只能存儲在應用程序域的LocalStorege中);
該圖像將使用帶<img>
元素的PhoneGap \\ Cordova HTML標記顯示;
使用<img src="xyz"/>
無效;
該解決方案與Android版本完全不同。
必須執行以下步驟:
從本地存儲加載圖像作為二進制數據;
將其放置在已編碼的img元素的“ src”屬性中;
碼:
var fileName = 'myappname/test.png';
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFail);
function onFileSystemSuccess (fileSystem) {
fileSystem.root.getFile(fileName, null, gotFileEntry, onFail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(onGotFile, onFail);
}
function gotFile(onGotFile) {
var reader = new FileReader();
reader.onloadend = function (evt) {
$('#outerDiv').html('<img src="' + evt.target.result + '" />');
};
reader.readAsDataURL(file);
}
function onFail(evt) {
console.log('error: ' + evt.target.error.code);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.