用canvas画了一个圆环进度条,发现会出现锯齿,有没有什么办法能避免或者清除锯齿?

<div id=app>
    <canvas id="deposit_canvas" class="deposit_canvas" ></canvas>
</div>

var app = new Vue({
            el : '#app',
            data : {
                process : 0
            },
            methods : {
                //渐变进度环
                shadowRing : function () {
                var canvas =document.querySelector('.deposit_canvas');     
                canvas.width = 150;
                canvas.height = 150;
                var ctx = canvas.getContext('2d');       
                ctx.lineWidth = 5;                    
                // 画灰色的圆
                ctx.beginPath();
                ctx.moveTo(145,75);
                ctx.strokeStyle = '#F6F6F6';
                ctx.arc(75,75,70,0, Math.PI * 2);
                ctx.stroke();
                animate();
                function animate(){
                    requestAnimationFrame(function (){
                        app.process += 1 ;
                        drawCricle(ctx, app.process);
                        if (app.process < 100) {
                            animate();
                        }
                    });
                }
                function drawCricle(ctx, percent) {
                     //画进度环
                     ctx.beginPath();
                     ctx.moveTo(75,5);
                     var grd=ctx.createLinearGradient(0,0,150,150);
                     grd.addColorStop(0,"#fea800");
                     grd.addColorStop(1,"#ff7c00");
                     ctx.strokeStyle = grd;
                     ctx.arc(75,75,70,Math.PI * 1.5, Math.PI * (1.5 + 2 * percent / 100 ));
                     ctx.stroke();
                }
            },    
            mounted : function() {
                    this.shadowRing();
            }
        });

图片描述

阅读 3.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进