繁体   English   中英

在Windows Phone 7的PhoneGap / Cordovia上以HTML显示LocalStore中的图像

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM