我这里有一些代码:
function cam(){
navigator.camera.getPicture(photoSave, onFail, { quality:
50});
}
function photoSave(imageURI) {
var imgFileName = imageURI.substr(imageURI.lastIndexOf('/')
+1);
var imgPath = "tmp/" + imgFileName;
console.log(imgFileName);
var gotFileEntry = function(fileEntry) {
alert("got image file entry: " +
fileEntry.fullPath);
var gotFileSystem = function(fileSystem){
// copy the file
fileEntry.copyTo(fileSystem.root, null,
copiedFile, fsFail);
};
// get file system to copy or move image file to
window.requestFileSystem(LocalFileSystem.PERSISTENT,
0, gotFileSystem, fsFail);};
window.resolveLocalFileSystemURI(imageURI, gotFileEntry,
fsFail);
}
function copiedFile(fileEntry) {
alert("copied file: " + fileEntry.fullPath);
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = fileEntry.toURI() + "?" + (new
Date()).getTime();
imagepath = fileEntry.fullPath;
alert(imagepath);
}
// file system fail
function fsFail(error) {
console.log("failed with error code: " + error.code);
};
// camera fail
function onFail(message) {
alert('Failed because: ' + message);
}
我能够将相机拍摄的图像的文件路径(使用 PhoneGap API)存储到我的数据库中。但是,当我使用 SELECT 语句检索图像时,如何将该文件路径显示为 HTML 页面上的实际图像呢?通常我会执行 $('selector').val(row['somecolumn']) 但如何对图像执行此操作?谢谢
编辑:在我的数据库行中,路径看起来像这样/cdv_photo_001.jpg 并且在我的 HTML 页面上,我的 img 标签的 id 为“largeImage”。我只是不知道如何从路径中获取实际图像并将其显示在该 img 标签中。希望这是有道理的。
最佳答案
尝试使用:
$('#largeImage').attr('src', row['rowname']);
这样,您就可以将图像的 src 指定为数据库内的路径。图像将显示在页面上
关于javascript - 从 SQLite 检索图像并在 HTML 页面上显示图像 - JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23322671/