我在Phonegap 1.5.0工作,我们的项目需要复制使用Android设备从相机拍摄的图片并将其移动到另一个文件夹.所有的图像都存储在DCIM/100 media/camera.如何将这些图像移动到另一个文件夹?我使用HTC Wildfire S.我引用了这个链接,先谢谢你了。
58wvjzkj1#
以下是对我有效的解决方案(从this answer扩展为user899641)。捕获的图像将被重命名并移动到自定义文件夹(在本例中,移动到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); }; }
tyg4sfes2#
如果你在拍照时使用FILE_URI方法,你可以将结果传递给window.resolveLocalFileSystemURI以获取FileEntry对象。然后你可以调用FileEntry上的copyTo方法。
mspsb9vt3#
也看看这个链接。http://docs.phonegap.com/en/1.4.1/phonegap_file_file.md.html#File在你捕获照片后,你将返回图片的路径,你可以用它来保存它到另一个位置使用文件API.只是读和写
3条答案
按热度按时间58wvjzkj1#
以下是对我有效的解决方案(从this answer扩展为user899641)。捕获的图像将被重命名并移动到自定义文件夹(在本例中,移动到SD卡中的文件夹**TestFolder*)
tyg4sfes2#
如果你在拍照时使用FILE_URI方法,你可以将结果传递给window.resolveLocalFileSystemURI以获取FileEntry对象。然后你可以调用FileEntry上的copyTo方法。
mspsb9vt3#
也看看这个链接。http://docs.phonegap.com/en/1.4.1/phonegap_file_file.md.html#File
在你捕获照片后,你将返回图片的路径,你可以用它来保存它到另一个位置使用文件API.只是读和写