小编use*_*588的帖子

无法从phonegap:android中的sdcard读取图像文件

我是一个手机新手.我正在尝试使用phonegap官方教程从android中的sdcard读取和映像文件.问题是图像没有显示而是在其位置出现问号.

我的代码:

var pictureSource;  
var destinationType;  


document.addEventListener("deviceready",onDeviceReady,false);


function onDeviceReady(){ 

   document.getElementById("test").innerHTML="onready about to request";
   window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, onFail);}





function onFail(message) {
  alert('Failed because: ' + message);
}
function gotFS(fileSystem) {
    fileSystem.root.getFile("1.jpg", null, 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 = reader.readAsDataURL(file);

}



function fail(evt) {
    console.log(evt.target.error.code);
}



</script>
Run Code Online (Sandbox Code Playgroud)

编辑:使用API​​ 16和min-sdk8"smallImage"是一个标签,它可以正常使用onphotodatasuccess.所以,相机在这里不是问题.与相机功能相关的一切都可以.从SD卡中读取在赋值声明中构成问题.
document.getElementById("smallImage").src = reader.readAsDataURL(file); 如果我添加这个我得到字符串和未知的铬错误-6,否则我看到通常的图像转换字符串.谢谢

android cordova

8
推荐指数
1
解决办法
7666
查看次数

标签 统计

android ×1

cordova ×1