【问题标题】:how can i access camera and take picture using phonegap framework7 template?如何使用 phonegap framework7 模板访问相机和拍照?
【发布时间】:2019-01-26 16:48:25
【问题描述】:

我需要使用相机权限才能拍摄。我使用了 framework7 模板。 我尝试了一些不同的方法,但都失败了。

【问题讨论】:

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


    【解决方案1】:

    使用过的插件
    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);
                                                   }
                                                   );
    
    
                }
    

    【讨论】:

    • tnx 你这么多哥们
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-19
    • 2021-08-09
    • 1970-01-01
    • 2011-10-07
    • 2012-05-30
    • 1970-01-01
    相关资源
    最近更新 更多