首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AppGyver安卓显示截图问题

AppGyver安卓显示截图问题
EN

Stack Overflow用户
提问于 2015-10-21 14:23:57
回答 1查看 99关注 0票数 0

我需要在我的ApGyver类固醇应用程序中显示捕获的图像。我捕获图像,然后尝试在图像中设置src。但它给我的错误是不允许本地资源:

我是这样捕捉图像的:

代码语言:javascript
复制
            var options = {
                quality: 50,
                targetWidth: 300,
                targetHeight: 300,
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.CAMERA, // Camera.PictureSourceType.PHOTOLIBRARY
                allowEdit: false,
                encodingType: Camera.EncodingType.JPEG,
                popoverOptions: CameraPopoverOptions,
                saveToPhotoAlbum: true,
                limit: 1
            };
            // capture callback
            var captureSuccess = function(mediaFiles) {
                var i, path, len;
                console.log(mediaFiles);
                for (i = 0, len = mediaFiles.length; i < len; i += 1) {
                    path = mediaFiles[i].localURL;
                    // do something interesting with the file
                }
                if (switched) {
                    $scope.post.media = []
                }
                $scope.post.media.length = 1;
                $scope.post.fileUrl = path;
                setActionType('image');
                $scope.isBusy = false;
                console.log('hello' + path);
            };

            // capture error callback
            var captureError = function(error) {
                navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
            };

            // start image capture
            navigator.device.capture.captureImage(captureSuccess, captureError, options);
EN

回答 1

Stack Overflow用户

发布于 2015-10-21 15:27:19

尝试使用此代码来捕获和上传图像。并在您的index.html链接cordova.js和添加相机插件ok。还有任何问题都会给我留言。

代码语言:javascript
复制
function capturePhoto() {
         navigator.camera.getPicture(uploadPhoto, onFail, {
         quality: 50, 
         // allowEdit: true,
         correctOrientation: true,
         destinationType: Camera.DestinationType.FILE_URL,
         // destinationType: Camera.DestinationType.DATA_URL
         sourceType: Camera.PictureSourceType.CAMERA
     });
    }

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

    function uploadPhoto(imageURI){
    console.log(imageURI);

    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType="image/jpeg";

    var ft = new FileTransfer();
    ft.upload(imageURI, encodeURI("http://XYZ/uploadimg?user_id="+UserId+""),  winGallary, fail, options);
    console.log(ft.upload);
    }

    function winGallary(rGallary) {
        console.log("Code = " + rGallary.responseCode);
        console.log("Response = " + rGallary.response);
        console.log("Sent = " + rGallary.bytesSent);

    }

    function fail(error) {
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33252328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档