如何使用phonegap framework7模板访问相机并拍照?

时间:2019-01-26 16:48:25

标签: camera phonegap html-framework-7 camera-api

我需要相机访问权限。我已经使用framework7模板。 我尝试了几种不同的方法,但是失败了。

1 个答案:

答案 0 :(得分:0)

使用的插件
1. cordova-plugin-actionsheet
2。cordova-plugin-camera

设计...

<div id="Photos">
                <a href="#" onclick="ImageSourceShareSheet()" style="text-decoration:none">
                <p class="footermenutext">Photos</p>
                </a>
                </div>

JavaScript

//Onclick Event for Photos Icon
            function ImageSourceShareSheet() {

                 //Options for Customize Actionsheet
                var options = {
                    'title': 'Select Image Source',
                    'buttonLabels': ['Camera', 'Photo Library'],
                    'addCancelButtonWithLabel': 'Cancel',
                    'position': [20, 40] // for iPad pass in the [x, y] position of the popover
                };

                window.plugins.actionsheet.show(options, callback);



            }

//Actionsheet Callback function
           function callback(buttonIndex) {

                    switch (buttonIndex) {
                    case 1:
                    capturePhoto();
                    break;
                    case 2:
                    SelectPhotosfromLibrary();
                    break;

                }
            }

             //Take image source from Camera
             function capturePhoto() {

              // Take picture using device camera and retrieve image as base64-encoded string
              navigator.camera.getPicture(onPhotoDataSuccess, onFail,{
                                          quality : 25,
                                          destinationType : Camera.DestinationType.FILE_URI,
                                          sourceType : Camera.PictureSourceType.CAMERA,
                                          allowEdit : true,
                                          encodingType: Camera.EncodingType.JPEG,
                                          popoverOptions: CameraPopoverOptions,
                                          saveToPhotoAlbum: true });
             }

             function SelectPhotosfromLibrary() {

                window.imagePicker.getPictures(
                                               function(results) {
                                               alert(JSON.stringify(results));

                                               if(results.length != 0)
                                               {
                                                // Photo Selected
                                               }
                                               else
                                               {
                                               // No photos Selected!

                                               }
                                               }, function (error) {
                                               console.log('Error: ' + error);
                                               }
                                               );


            }