zoukankan      html  css  js  c++  java
  • canvas画线 文本 填充

    <!doctype html>
    <html lang="en">

    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="chrome=1">
      <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
      <style>
        * {
          padding: 0;
          margin: 0;
          box-sizing: border-box;
        }
      </style>

    </head>

    <body>
      <img id="img" width="50px" height="50px" src="">

      <script>
       function createImg(distance, color,text) {
            var c = document.createElement("canvas");
            c.width = distance; //注意:没有单位
            c.height = distance; //注意:没有单位
            var ctx = c.getContext("2d");
            ctx.beginPath();
            ctx.fillStyle ="green";
             ctx.fillRect(0, 0, distance, distance);
            ctx.moveTo (0,0);       
            ctx.lineTo (0,distance);  
            ctx.lineTo (distance,distance);   
            ctx.lineTo (distance,0);   
            ctx.lineTo (0,0); 
            ctx.lineWidth = 1;          
            ctx.strokeStyle = color;  
            ctx.stroke();    
            ctx.textAlign = 'center';
            ctx.font = "bold "+distance/10+"px Arial";
            ctx.fillStyle = 'yellow';
            ctx.fillText(text, distance / 2, distance / 2+3);
            return c.toDataURL("image/png");
          }
          document.getElementById('img').src= createImg(50, "red","833336")
      </script>
    </body>

    </html>
  • 相关阅读:
    1289 大鱼吃小鱼
    install ios开发环境
    Xcode_5
    嵌入式学习_AD学习篇
    课务IOS概述_1
    动态规划入门(2):01背包问题
    Python记之薄暮笔记
    线段树进阶:权值线段树
    动态规划入门(1):最长递增子序列
    python记之Hello world!
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/12459281.html
Copyright © 2011-2022 走看看