html - 使用cordova插件的图像在 Canvas 上看起来很糟糕

标签 html ios cordova html5-canvas cordova-plugins

我正在为我的 ios 应用程序使用 cordova 来捕获图像 horrible draw on canvas

代码看起来

  navigator.camera.getPicture(onSuccessCamera, onFailureCamera, {
                                    quality: 25,
                                    destinationType: navigator.camera.DestinationType.DATA_URL,
                                    correctOrientation: true,
                                    allowEdit:false
                                    });


function onSuccessCamera(imageURI) {                     
          var imgData = "data:image/jpeg;base64," + imageURI;
          uploadFile(imgData);
                                  }

function uploadFile(file){
 var c=document.getElementById("picture");

                                                c.width = window.innerWidth-50;//offset to prevent image flowing out of frame
                                                //  window.alert(window.innerWidth+":"+ window.innerHeight);414:736
                                                c.height = "330";//window.innerHeight;//this.height;
                                                var ctx=c.getContext("2d");
                                                var showImg = new Image();
                                                showImg.onload = function(){

                                                    var ratio = 1;
                                                    if (this.height > c.height) {
                                                        ratio = c.height/this.height;
                                                    }
                                                    else if (this.width>c.width) {
                                                        ratio = c.width/this.width;
                                                    }



                                                    ctx.drawImage(this,0,0, this.width*ratio, this.height*ratio);
                                                    // window.alert(c.width + ':' + c.height);
                                                };
                                                showImg.src = file;
}

我不知道为什么图像看起来如此可怕

最佳答案

这是因为视网膜屏幕。

将 Canvas 的高度和宽度设为双倍,然后将其设置为半像素

c.width = (window.innerWidth-50)*2;//offset to prevent image flowing out of frame
c.height = 330*2;//window.innerHeight;//this.height;

c.style.width = (c.width/2)+"px";
c.style.height = (c.height/2)+"px";

此外,您可以考虑在 quality 上使用更高的值。相机选项。

关于html - 使用cordova插件的图像在 Canvas 上看起来很糟糕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44089324/

相关文章:

jquery - 更改 Bootstrap 插入符号的轮廓颜色

html - 文本输入在 Chrome 中保持水平滚动, "text-overflow: ellipsis"

ios - 无法使用带有电子邮件/密码的 Firebase 简单登录来执行完成 block

javascript - Textarea 在 IOS 上只允许输入一个字符。如何解决?

javascript - ReactJS 与 Cordova 在解析 js/css 源方面存在冲突。如何解决?

android - 无法使用 Phonegap Build 在应用程序中注册 PushPlugin?

javascript - 使用 javascript 进行简单测验

php - 上传一个word文档,存储到mysql上并显示

ios - 将 fft 计算与 View Controller 分开

ios - 创建数学视频库应用程序。需要有关如何存储数据的建议