简体   繁体   English

navigator.camera.getPicture无法正常工作

[英]navigator.camera.getPicture not working properly

In my cordova(v3.3) single page application use the following code to get the camera image 在我的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);

};
}

The above code working fine in NEXUS 7(v 4.2) device and alerts the camera start but in samsung tab 4(v 4.4) devices the alert camera start never fires first time but it goes to camera and able to take picture but not able to save. 上面的代码在NEXUS 7(v 4.2)设备中可以正常工作并警告相机启动,但在三星选项卡4(v 4.4)设备中,警告相机启动从不触发,但它goes to camera and able to take picture but not able to save.

when again take the new image at the time only the old image get stored. 当再次拍摄新图像时,仅存储旧图像。 like wise take new image only the previous image stored. 像明智的做法是只存储先前的图像来获取新图像。 How to solve this. 如何解决这个问题。 Any help is highly appreciable. 任何帮助都是非常明显的。

To save an image you need to configure options properly. 要保存图像,您需要正确配置选项。

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
   });
} 

The saveToPhotoAlbum : true is required to save image. saveToPhotoAlbum : true保存图像所必需的。

Update: 更新:

To save file in a custom location, you have to use File plugin . 要将文件保存在自定义位置,您必须使用File plugin

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cordova navigator.camera.getPicture 在 android 中不起作用 - cordova navigator.camera.getPicture not working in android navigator.camera.getPicture在android中不起作用 - navigator.camera.getPicture not working in android 画廊错误中的navigator.camera.getPicture错误“无法创建位图” - navigator.camera.getPicture from the gallery error “Unable to create bitmap” PhoneGap navigator.camera.getPicture不触发回调 - PhoneGap navigator.camera.getPicture don't trigger Callback navigator.camera.getPicture不打开设备的默认相机应用程序 - navigator.camera.getPicture dont opens the device's default camera application Cordova navigator.camera.getPicture在Android 4.4 KitKat上以意外格式返回FILE_URI - Cordova navigator.camera.getPicture returns FILE_URI in unexpected format on Android 4.4 KitKat from gallery ionic navigator.camera.getPicture不会从PHOTOLIBRARY返回图像 - ionic navigator.camera.getPicture won't return image from PHOTOLIBRARY navigator.camera.getPicture不会调用成功回调 - 离子框架 - cordova - navigator.camera.getPicture doesn’t call success callback - ionic framework - cordova 为什么我不能在Android应用中使用Cordova 2.7.0触发navigator.camera.getPicture? - Why can't I trigger navigator.camera.getPicture using Cordova 2.7.0 in my Android app? 错误:使用navigator.camera.getPicture()时出现“不允许加载本地资源” - Error: “Not allowed to load local resource” when using navigator.camera.getPicture()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM