• canvas下载图片


    canvas下载图片

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            canvas{ border: 1px solid black; }
        </style>
    </head>
    <body>
        <canvas id="myCanvas" width="500" height="500"></canvas>
        <a download="canvas.jpg" href="" onclick="downloadpic(this);">下载图片</a>
        <script>
            var canvas = document.getElementById("myCanvas");
            var ox = canvas.width / 2;
            var oy = canvas.height / 2;
    
            var ctx = canvas.getContext("2d");
            ctx.font = "42px serif";
            ctx.textAlign = "center";
            ctx.textBaseline = "middle";
            ctx.fillText("Hello World", ox, oy);
    
            function downloadpic(e) {
                var image = canvas.toDataURL("image/jpg", 1);
                e.href = image;
            };
        </script>
    </body>
    </html>
    
  • 相关阅读:
    lua module
    lua require
    lua io
    lua table2
    lua table1
    【leetcode】魔术排列
    【leetcode】速算机器人
    【leetcode】黑白方格画
    【leetcode】根据数字二进制下 1 的数目排序
    【leetcode】插入区间
  • 原文地址:https://www.cnblogs.com/ye-hcj/p/10356406.html
Copyright © 2020-2023  润新知