phonegap相机错误类型

时间:2014-03-21 07:43:50

标签: javascript cordova

我正在使用phonegap / cordova 3.3相机api。当我调用camera.getPicture方法时,您可以设置onError函数。 发生错误时,会返回一个数字,例如。 1:用户中止/取消拍照。

现在的问题是:文档在哪里? Wat做的所有代码都意味着什么?

2 个答案:

答案 0 :(得分:0)

您需要安装相机cordova插件

https://github.com/apache/cordova-plugin-camera

然后你可以在这里查看文档:

https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md

确保在项目中实施这些代码。

的javascript

var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
 //
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
 //

function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
    pictureSource = navigator.camera.PictureSourceType;
    destinationType = navigator.camera.DestinationType;
    checkConnection();
}

function onFileSystemSuccess(fileSystem) {
    console.log(fileSystem.name);
    console.log(fileSystem.root.name);
}

function fail(error) {
    console.log(error.code);
}
// Called when a photo is successfully retrieved
 //

function onPhotoDataSuccess(imageURI) {
    // Uncomment to view the base64-encoded image data
    console.log(imageURI);
    // Get image handle
    //
    var smallImage = document.getElementById('image');
    // Unhide image elements
    //
    smallImage.style.display = 'block';
    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    smallImage.src = imageURI;
    localStorage.imageUrl = imageURI;
}
// Called when a photo is successfully retrieved
 //

function onPhotoURISuccess(imageURI) {
    // Uncomment to view the image file URI
     console.log(imageURI);
    // Get image handle
    //
    var largeImage = document.getElementById('image');
    // Unhide image elements
    //
    largeImage.style.display = 'block';
    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    largeImage.src = imageURI;
    localStorage.imageUrl = imageURI;
}
// A button will call this function
 //

function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
        quality: 50,
        destinationType: destinationType.FILE_URI,
        saveToPhotoAlbum: true
    });
}
// A button will call this function
 //

function capturePhotoEdit() {
    // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
        quality: 20,
        allowEdit: true,
        destinationType: destinationType.FILE_URI
    });
}
// A button will call this function
 //

function getPhoto(source) {
    // Retrieve image file location from specified source
    navigator.camera.getPicture(onPhotoURISuccess, onFail, {
        quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source
    });
}
// Called if something bad happens.
 //

function onFail(message) {
    alert('Failed because: ' + message);
}

HTML

<button onclick="capturePhoto();">Capture Photo</button><br />
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo
Library</button> <img id="image" name="image" src="" style=
"display:none;width:100%;" />

答案 1 :(得分:0)

啊我有点困惑按钮错误是nog代码但是消息。有点不幸的是,每个平台上的错误信息都不同......