zoukankan      html  css  js  c++  java
  • canvas绘图出现模糊,解决方法

    在项目开发中发现,canvas有一个问题,绘制的图会出现模糊现象。

    解决方法之一:将canvas元素放大2倍,然后将整个canvas元素或者其父元素缩小两倍。

    <!DOCTYPE html>
    <html>
    
    <body>
      <canvas id="myCanvas" width="400" height="300" style="border:1px solid #d3d3d3;">
        Your browser does not support the HTML5 canvas tag.
      </canvas>
      
      <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        ctx.beginPath();
        ctx.fillStyle = "yellow";
        ctx.arc(200, 150, 100, 0, 2 * Math.PI);
        ctx.stroke();
        ctx.fill();
      </script>
    
    </body>
    
    </html>

    <!DOCTYPE html>
    <html>
    <head>
      <style>
        .box {
          zoom: 0.5;
        }
      </style>
    </head>
    
    <body>
      <div class="box">
        <canvas id="myCanvas" width="800" height="600" style="border:1px solid #d3d3d3;">
          Your browser does not support the HTML5 canvas tag.
        </canvas>
    
      </div>
      <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        ctx.scale(2, 2); // 放大2倍
        ctx.beginPath();
        ctx.fillStyle = "yellow";
        ctx.arc(200, 150, 100, 0, 2 * Math.PI);
        ctx.stroke();
        ctx.fill();
    
      </script>
    
    </body>
    
    </html>

  • 相关阅读:
    svn:ignore 设置忽略文件
    Css让文字自适应Table宽度[转]
    自学python笔记
    java代码中添加log4j日志
    maven多模块项目搭建
    js || 与&&
    java内存溢出和tomcat内存配置
    xsl:for-each中引用循环外全局变量
    quartz启动两次(tomcat)
    pymysql简单封装
  • 原文地址:https://www.cnblogs.com/wanf/p/10250144.html
Copyright © 2011-2022 走看看