在HTML5画布中锐化绘图

Mat5i6

今天,我开始通过制作基本的加载圆圈动画来学习如何使用画布。一切都可以在较小的分辨率(约100×100像素)下完美显示,但是当我尝试更大的分辨率时,一切都变得失真和模糊,看起来真的很糟糕。所以这是我的问题:我可以以某种方式打开某些抗锯齿功能还是以某种方式使其更加清晰?我已经找到了很多锐化算法,但是对于图像,我不确定是否可以使用。

循环加载示例:(代码不是完美的,甚至还没有完成,因为我仍然停留在模糊中)

JSFiddle

var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
var int_count = 0;
var circ_angle = 1.5;
var count = 10;

var interval = setInterval(function() {

  if (int_count == count) {
    clearInterval(interval);
  }
  ctx.clearRect(0, 0, 1000, 1000);

  ctx.beginPath();

  ctx.arc(100, 70, 50, 1.5 * Math.PI, -1 * Math.PI, true);
  ctx.lineWidth = 1;
  ctx.strokeStyle = "#717171";
  ctx.stroke();

  ctx.beginPath();

  //1.5 = 0%; 1 = 1/4; 0.5 = 2/4; 0 = 3/4 -1 = full
  ctx.font = "40px sarpanch";
  ctx.arc(100, 70, 50, 1.5 * Math.PI, circ_angle * Math.PI, true);
  //color
  if (int_count >= 5 && int_count < 10) {
    ctx.strokeStyle = "#ff8000";
  }
  else if (int_count >= 9) {
    ctx.strokeStyle = "#F00";
  }
  else {
    ctx.strokeStyle = "#3a9fbe";
  }

  ctx.fillText("" + int_count + "", 88, 83);

  ctx.lineWidth = 3;
  ctx.stroke();

  int_count += 1;
  circ_angle += (-0.2);
}, 500);
月桂胺

添加以下属性:

width="759" height="394"

到您的位置,<canvas>而不是在您的CSS中指定它们

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章