简体   繁体   English

html5 canvas toDataURL在移动设备上的图片质量较差

[英]html5 canvas toDataURL poor image quality on mobile

I'm using the toDataURL("image/png") function. 我正在使用toDataURL("image/png")函数。 My canvas has several lines, colored shapes and text. 我的画布有几行,彩色的形状和文本。 The resulting png looks good on desktop Chrome. 生成的png在台式机Chrome上看起来不错。 However, the image is very low quality, pixelated, on mobile Chrome. 但是,该图片在移动版Chrome上的像素质量很低。

Is there a way to improve image quality for mobile devices? 有没有一种方法可以改善移动设备的图像质量?

You can set the canvas CSS size smaller than the canvas element size. 您可以将canvas CSS大小设置为小于canvas元素大小。

This causes the browser to draw more "densely" on the canvas. 这导致浏览器在画布上绘制得更“密集”。

HTML: HTML:

<canvas id="canvas" width=600 height=300></canvas>

CSS: CSS:

#canvas {
    width:300px;
    height:150px;
}        

A Demo: http://jsfiddle.net/m1erickson/N8JL6/ 演示: http : //jsfiddle.net/m1erickson/N8JL6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM