如何使用 Phonegap 将 Android 手机拍摄的图像移动到另一个文件夹

问题描述 投票:0回答:3

我正在开发 Phonegap 1.5.0,我们的项目需要复制使用 Android 设备从相机拍摄的照片并将其移动到另一个文件夹。所有图像都存储在 DCIM/100media/camera 中。 如何将这些图像移动到另一个文件夹?我正在使用 HTC Wildfire S。

我已经提到了这个link,

提前致谢。

android cordova
3个回答
4
投票

这是对我有用的解决方案(由user899641this answer扩展而来)。捕获的图像将被重命名并移动到自定义文件夹(在本例中,移动到 SD 卡 中的文件夹TestFolder

function capture() {

    // Retrieve image file location from specified source
    navigator.camera.getPicture(getImageURI, function(message) {
        alert('Image Capture Failed');
    }, {
        quality : 40,
        destinationType : Camera.DestinationType.FILE_URI
    });

}

function getImageURI(imageURI) {

    var gotFileEntry = function(fileEntry) {
        alert("got image file entry: " + fileEntry.fullPath);
        var gotFileSystem = function(fileSystem) {

            fileSystem.root.getDirectory("TestFolder", {
                create : true
            }, function(dataDir) {

                // copy the file
                fileEntry.moveTo(dataDir, "1.jpg", null, fsFail);

            }, dirFail);

        };
        // get file system to copy or move image file to
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem,
                fsFail);
    };
    // resolve file system for image
    window.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail);

    // file system fail
    var fsFail = function(error) {
        alert("failed with error code: " + error.code);

    };

    var dirFail = function(error) {
        alert("Directory error code: " + error.code);

    };
}

2
投票

如果您在拍照时使用 FILE_URI 方法,您可以将该结果传递给 window.resolveLocalFileSystemURI 以获取 FileEntry 对象。然后你可以在 FileEntry 上调用 copyTo 方法。


1
投票

然后也看看这个链接 ;) http://docs.phonegap.com/en/1.4.1/phonegap_file_file.md.html#File
拍摄照片后,您将返回图片的路径,您可以使用它使用文件 api 将其保存到另一个位置。只是读写

© www.soinside.com 2019 - 2024. All rights reserved.