简体   繁体   中英

How to show a jpg image file from sd card in phonegap?

What I am trying to do here is to show an jpg image from the data directory of the android phone, not an image captured by the phone camera. Here is my code I have got to so far:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess);
}
function onFileSystemSuccess(fileSystem){
    fileSystem.root.getDirectory("../data", {create: false, exclusive: false}, dirSuccess);
}
function dirSuccess(getDir){
    getDir.getFile("test.jpg", {create: false, exclusive: false}, fileSuccess);
}

I have two things to be confirmed about here. Firstly, will my code get me to the desired image file?? I mean if there is any error so far?? And secondly, where I am stuck actually, What I need to do to show the image on the app page?? just write the image file name in the src of img tag under fileSuccess method?? or something else?? I am new to phonegap and javascript. May be it's a easy problem. But still, please help me. Thank you...:)

您可以通过使用此插件检索图像的Base64编码,然后将其分配给image src属性来实现。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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