![](/img/trans.png)
[英]cordova navigator.camera.getPicture not working in android
[英]navigator.camera.getPicture not working properly
在我的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)設備中,警告相機啟動從不觸發,但它goes to camera and able to take picture but not able to save.
當再次拍攝新圖像時,僅存儲舊圖像。 像明智的做法是只存儲先前的圖像來獲取新圖像。 如何解決這個問題。 任何幫助都是非常明顯的。
要保存圖像,您需要正確配置選項。
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 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.