【发布时间】:2013-09-17 11:10:56
【问题描述】:
我想将图像源分配给 html 中的 img 标签。图像保存在 sdcard 的自定义文件夹中。请帮我这样做。我对此进行了很多搜索,但没有任何帮助。
【问题讨论】:
标签: android image cordova android-sdcard src
我想将图像源分配给 html 中的 img 标签。图像保存在 sdcard 的自定义文件夹中。请帮我这样做。我对此进行了很多搜索,但没有任何帮助。
【问题讨论】:
标签: android image cordova android-sdcard src
我只是通过提供路径来解决它
<img src="file:///mnt/sdcard/abc/def/ghi/xyz.png"/>
【讨论】:
这就是我将如何解决您的问题:
function getPathToCustomFolder(callback)
{
var customFolderName = "myFunnyImages"
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSys) {
fileSys.root.getDirectory(customFolderName, {create: true, exclusive: false},
function(dir){
callback(dir.fullPath);
})
}, error
);
}
// After calling this function, you will get the path of your customFolder
function alertThePath()
{
getPathToCustomFolder(
function(result){
alert(result);
});
}
// Changes your scr attribute
function showMyImage()
{
var image = document.getElementById('funnyImage');
getPathToCustomFolder(
function(result){
image.src = result+"/funny1.jpg";
});
}
有关更多信息,请查看 phonegap FileAPI。
【讨论】: