gpt4 book ai didi

cordova - Phonegap-通过路径从相机胶卷检索照片

转载 作者:行者123 更新时间:2023-12-03 12:17:55 24 4
gpt4 key购买 nike

在我的PhoneGap / jQuery Mobile应用程序中,我当前正在使用PhoneGaps的Camera API来允许用户拍摄照片,该照片也存储在Camera Roll中。我将DestinationType设置为FILE_URI并将此路径保存在本地数据库中。但是,FILE_URI是指向临时位置的路径,该路径在应用程序关闭时会被破坏。我当时想保存图像的名称,然后从“相机胶卷”中检索图像。有没有我以后可以用来在相机胶卷中检索图像的路径?

我将图像保存为db中的Base64,但是由于PhoneGap API Doc中的这一注释,我对此方法有些厌倦:

Note: The image quality of pictures taken using the camera on newer devices is quite good. Encoding such images using Base64 has caused memory issues on some of these devices (iPhone 4, BlackBerry Torch 9800). Therefore, using FILE_URI as the 'Camera.destinationType' is highly recommended.



编辑:

与@Simon MacDonald的答案一起使用。这是我的简化代码:
function capturePhoto() {
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 25, destinationType: Camera.DestinationType.FILE_URI });
}

function onPhotoURISuccess(imageURI) {
createFileEntry(imageURI);
}

function createFileEntry(imageURI) {
window.resolveLocalFileSystemURI(imageURI, copyPhoto, fail);
}

function copyPhoto(fileEntry) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
fileSys.root.getDirectory("photos", {create: true, exclusive: false}, function(dir) {
fileEntry.copyTo(dir, "file.jpg", onCopySuccess, fail);
}, fail);
}, fail);
}

function onCopySuccess(entry) {
console.log(entry.fullPath)
}

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

最佳答案

使用FILE_URI方法检索文件后,应使用File API将图像从temp文件夹复制到Documents文件夹,并将新路径存储在数据库中。

因此,您将把getPicture()的结果传递给window.resolveLocalFileSystemURI()以获得FileEntry。然后,您可以调用FileEntry.copyTo()方法来备份文件。

关于cordova - Phonegap-通过路径从相机胶卷检索照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9180731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com