1

它是 phonegap 中的网络应用程序,我使用 320 x 480 的图像进行绘制,但它很模糊。

html

<canvas id="canvas" height=480 width=320>
Your browser does not support the HTML5 canvas tag.</canvas>

javascript

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.drawImage(images[index],0,0,320,480);

如何在视网膜显示屏上清晰地绘制?

4

2 回答 2

5

如果您可以访问更大版本的图像,则可以将可见分辨率提高一倍。

源图像需要为 640x960:

这是将图像分辨率“像素加倍”的代码。

canvas.width = 640;
canvas.height = 960;
canvas.style.width = "320px";
canvas.style.height = "480px";

如果没有,您可以使用相同的“像素加倍”效果,并使用现有图像呈现更小但更清晰的版本:

canvas.width = 320;
canvas.height = 480;
canvas.style.width = "160px";
canvas.style.height = "240px";
于 2013-07-11T02:51:48.813 回答
0

这是关于如何在画布上绘制(任何东西)以使其在视网膜显示器或任何高 DPI 显示器上看起来清晰的一般答案。

通过以下方式获取屏幕密度:

var screenDensity = window.devicePixelRatio

然后只需将您的路径、笔画、字体大小、画布大小等与screenDensity.

例如:

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var screenDensity = window.devicePixelRatio;

// Make it visually fill the positioned parent
canvas.style.width = '100%';
canvas.style.height = '100%';
// ...then set the internal size to match
canvas.width = canvas.offsetWidth * screenDensity;
canvas.height = canvas.offsetHeight * screenDensity;

ctx.beginPath();
ctx.moveTo(42 * screenDensity, 0);
ctx.lineTo(42 * screenDensity, 4 * screenDensity);
// (...more stuff goes here...)
ctx.closePath();
ctx.strokeStyle = '#000000';
ctx.lineWidth = 2 * screenDensity;
ctx.stroke();

或者,您可以将画布设置scalescreenDensity. 有关更多信息和示例,请参见此处:https ://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio

于 2021-03-31T10:15:49.883 回答