首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >navigator.camera.getPicture工作不正常

navigator.camera.getPicture工作不正常
EN

Stack Overflow用户
提问于 2014-12-04 04:53:17
回答 1查看 2.7K关注 0票数 1

在我的cordova(v3.3)单页应用程序中,使用以下代码获取相机图像

代码语言:javascript
复制
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(v4.2)设备中运行良好,并提醒相机启动,但在三星选项卡4(v4.4)设备中,警报摄像头启动时不会第一次触发,但会触发goes to camera and able to take picture but not able to save.

当再次采取新的图像时,只有旧的图像被存储。像wise一样,只获取新的图像,只存储以前的图像。如何解决这个问题。任何帮助都是非常值得赞赏的。

EN

回答 1

Stack Overflow用户

发布于 2014-12-04 06:16:31

要保存图像,需要正确配置选项。

代码语言:javascript
复制
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保存映像所必需的。

更新:

要将文件保存到自定义位置,必须使用文件插件

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27286531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档