在我的cordova(v3.3)单页应用程序中,使用以下代码获取摄像机图像
function takeSkiImage(){
capturePhoto();
}
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
alert((navigator.camera.getPicture));
navigator.camera.cleanup();
navigator.camera.getPicture(onPhotoDataSuccess, function fail(error){
alert("failed : " + error.code);
}, {
quality : 90,
targetWidth : 2300,
targetHeight : 1800,
destinationType : Camera.DestinationType.FILE_URI
});
}
function onPhotoDataSuccess(imageURI) {
var gotFileEntry = function(fileEntry) {
alert("got image file entry: " + fileEntry.fullPath);
var gotFileSystem = function(fileSystem) {
fileSystem.root.getDirectory("sample", {
create : true
}, function(dataDir) {
var d = new Date();
var n = d.getTime();
var newFileName = n + ".jpg";
alert("File Downloaded");
// copy the file
fileEntry.moveTo(dataDir, newFileName, 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);
};
}
以上代码在 NEXUS 7(v 4.2)设备中正常工作并提醒相机启动,但在三星标签4(v 4.4)设备中,警报摄像头启动从未第一次启动< / strong>但goes to camera and able to take picture but not able to save.
当再次拍摄新图像时,只存储旧图像。喜欢明智地拍摄新图像只存储以前的图像。怎么解决这个问题。任何帮助都非常值得赞赏。
答案 0 :(得分:0)
要保存图像,您需要正确配置选项。
function takeSkiImage(){
alert("hi");
navigator.camera.getPicture(function(imageData) {
alert("camera start");
}, onFail, {
quality : 100, allowEdit : true,
targetWidth: 2350,
targetHeight: 1800,
destinationType : Camera.DestinationType.FILE_URI,
saveToPhotoAlbum : true
});
}
保存图片需要saveToPhotoAlbum : true
。
<强>更新强>
要将文件保存在自定义位置,您必须使用File plugin。