【问题标题】:How do i check for low resolution photos when using cordova camera plugin?使用cordova相机插件时如何检查低分辨率照片?
【发布时间】:2017-07-17 12:29:18
【问题描述】:

我有以下代码。它几乎适用于大部分时间。我想用蹩脚的相机捕捉人们,并警告他们他们的照片会发臭。 (使用“cordova-plugin-camera”版本 2.3.0)

           var cameraOpts = {
                quality: 100,
                // destinationType: Camera.DestinationType.FILE_URI,
                destinationType: Camera.DestinationType.DATA_URL,
                sourceType: $scope.sourceType,
                allowEdit: false,
                encodingType: Camera.EncodingType.JPEG,
                // popoverOptions: CameraPopoverOptions,
                targetWidth: 186,
                targetHeight: 1024,
                saveToPhotoAlbum: true,
                correctOrientation: true
            };

            $cordovaCamera.getPicture(cameraOpts).then(function(imageData) {
                var image = "data:image/jpeg;base64," + imageData;
                $scope.setUpImage(index,image);

            }, function(err) {
                // error
                $scope.showAlert('Warning!', 'Camera cancelled!');
            });

任何想法将不胜感激。我正在寻找一种捕捉低分辨率照片并向用户发送消息的方法。

【问题讨论】:

    标签: cordova camera cordova-plugins


    【解决方案1】:

    cordova 相机插件提供 quality 相机选项,但它不提供有关分辨率的任何信息(默认为 100)(enter link description here)

    【讨论】:

    • 我的画质设置为100,有时候图片还是很模糊。我认为这取决于用户的手机摄像头。
    • 100是android中的默认值,即使你通过50,android也不允许对图像进行下采样。
    • 获取图像后怎么样..有没有办法检查图像是否模糊?
    • 根据 android 文档,如果 MediaStore.EXTRA_OUTPUT 不存在,本机相机可以捕捉到模糊的图像。 MediaStore.EXTRA_OUTPUT 用于指定要保存的捕获图像的目标位置。在 cordova 中,这完全指定为缓存 location.link。所以没有办法得到一个模糊的图像。
    • 图片保存后怎么样? JS中有没有办法检测模糊图像? (相对而言?)比如“您在此设备上拍摄的图像很可能很模糊。我们建议您尝试使用其他设备。”?
    【解决方案2】:

    你应该创建一个 Image 对象(这是标准的 HTML5 API)

    从这个答案复制的相关sn-p:

    HTML5 - how to get image dimension

    来自插件文档:“图像作为 Base64 编码的字符串或图像文件的 URI 传递给成功回调”

    如果您在相机插件中选择base64格式,则数据URI将为

    'data:image/jpg;base64,' + imageData
    

    但是,插件文档推荐文件格式,它将返回一个文件 URL,您可以直接将其分配给您的 image.src

    var image = new Image();
            image.onload = function(evt) {
                var width = this.width;
                var height = this.height;
                alert (width); // will produce something like 198
            };
    
            //here is where you pass the camera data to create the image
    image.src = imageData; 
    

    如您所见,该方法是异步的,您可以将其包装在 Promise 中,或者在图像已加载且宽度 x 高度时发出事件

    【讨论】:

      猜你喜欢
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-11
      相关资源
      最近更新 更多