OGeek|极客世界-中国程序员成长平台

标题: javascript - Cordova iOS 相机插件返回空的 snapshop [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:49
标题: javascript - Cordova iOS 相机插件返回空的 snapshop

我有一个简单的基于 Cordova 的 APP,我正在使用相机和文件插件。 我拍照,在 Canvas 上绘画,用户可以添加一些图像并保存图像。

在 android 上一切正常,但在 iOS 上,我将其空白且无法在 Canvas 上绘制的图片,在 XCode 控制台上我收到:

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

我的相机代码是:

        navigator.camera.getPicture(
            function(imageData) {

                bgSrc = 'data:image/png;base64,' + imageData;
                bgImg.setAttribute('src', bgSrc);

                app.drawEditor(bgImg);
            },
            function(message) {
                alert('Failed because: ' + message);
                app.addClass('Home');
                app.drawMenu();
            }, {
                quality: 50,
                correctOrientation: true,
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: Camera.PictureSourceType.CAMERA,
                encodingType: Camera.EncodingType.JPEG,
                targetWidth: 720,
                saveToPhotoAlbum: false
            });

注意:我使用的是最新版本的 cordova 和来自 github 的最新版本的相机插件。

有人知道如何解决这个问题吗?



Best Answer-推荐答案


希望对您有所帮助:

                 function captureProfilePhoto(exec)
                      {
                              alert("captureProfilePhoto");
                             //alert("check");
                          navigator.camera.getPicture(function(imageURI){
                            exec(imageURI);
                            }, function(message){
                            alert("No attachment added");
                            //alert(labels.get("VPCS_GLOBAL_FAILURE_REASON_"+language)+" : " + message);
                            exec(-1);
                            }, {
                            quality : 100,
                            destinationType: navigator.camera.FILE_URI,
                            sourceType : Camera.PictureSourceType.CAMERA,
                            encodingType: Camera.EncodingType.JPEG,
                            targetWidth:960,
                            targetHeight:640,
                            correctOrientation: true,
                            allowEdit : true,
                            popoverOptions: CameraPopoverOptions });


                      }

//用ID调用上述方法:

                      $("#basicInfoCapturePhoto").click(function(){
                   captureProfilePhoto(function(imageURI){
                      if(imageURI != -1){
                       profileImageURI = imageURI;

                 });
              }

          });

关于javascript - Cordova iOS 相机插件返回空的 snapshop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31313774/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4