【问题标题】:How to get the raw image data from html being not compressed used javascript?如何从未压缩的 html 中获取原始图像数据?
【发布时间】:2015-05-07 13:50:07
【问题描述】:

我可以使用 javascript 从 html 中获取图像数据:

function imageClicked(e) {
            //alert(this.getAttribute("src"));
            var canvas = document.createElement("canvas");
            var context = canvas.getContext("2d");
            canvas.width = this.width;
            canvas.height = this.height;
            context.drawImage(this,0,0,this.width,this.height);
            loadURL(canvas.toDataURL("image/png"));
            e.stopPropagation();  // <=== Prevents the click reaching the div
        }

但是图片不像在html中显示的那么清晰,它被压缩了。如何让图像不被压缩? UIWebView中显示的原始图像如下,我们可以看到图像中的文字非常清晰:

下一张图是从javascript中得到的,然后显示出来,不是很清楚:

【问题讨论】:

    标签: javascript html ios image uiwebview


    【解决方案1】:

    这个answer 会帮助你,你需要设置第二个参数:

    canvas.toDataURL(type,quality);
    

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 2013-11-17
      • 2021-09-06
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 2013-01-01
      • 1970-01-01
      • 2017-03-22
      相关资源
      最近更新 更多