如何处理相机插件cordova 3.4有两个选项(CAMERA和SAVEDPHOTOALBUM)

时间:2014-05-23 03:02:59

标签: cordova camera

现在我开发移动应用程序cordova 3.4我知道已经使用相机插件。 但我只能使用(Camera.PictureSourceType.SAVEDPHOTOALBUM或Camera.PictureSourceType.CAMERA)选项。我想要两个。我不知道如何处理移动行为可以选择相机或选择画廊。请帮我解决这个问题。提前谢谢

1 个答案:

答案 0 :(得分:1)

这是JQuery部分:

/**
 * Take picture with camera
 */
function takePicture() {
    navigator.camera.getPicture(
        function(uri) {
            var img = document.getElementById('camera_image');
            img.style.visibility = "visible";
            img.style.display = "block";
            img.src = uri;
            document.getElementById('camera_status').innerHTML = "Success";
        },
        function(e) {
            console.log("Error getting picture: " + e);
            document.getElementById('camera_status').innerHTML = "Error getting picture.";
        },
        { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI});
};

/**
 * Select picture from library
 */
function selectPicture() {
    navigator.camera.getPicture(
        function(uri) {
            var img = document.getElementById('camera_image');
            img.style.visibility = "visible";
            img.style.display = "block";
            img.src = uri;
            document.getElementById('camera_status').innerHTML = "Success";
        },
        function(e) {
            console.log("Error getting picture: " + e);
            document.getElementById('camera_status').innerHTML = "Error getting picture.";
        },
        { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY});
};

这里是html部分

    <div>
    <input type="button" onclick="takePicture();" value="Take Picture" /><br/>
    <input type="button" onclick="selectPicture();" value="Select Picture from Library" /><br/>
</div>

我希望你找到了解决方案 感谢