链接转二维码+图片与canvas互转

2018-04-11  本文已影响0人  leesession

1.图片转canvas

function ImageToCanvas(image) {
    var canvas = document.createElement("canvas");
    canvas.width = image.width;
    canvas.height = image.height;
    canvas.getContext("2d").drawImage(image, 0, 0);
    return canvas;
}

2.canvas转图片

function CanvasToImage(canvas) {
    var image = new Image();
    image.src = canvas.toDataURL("image/png");
    return image;
}

3.链接转二维码
先引入
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
然后

$(document).ready(function(){
        $('#code').qrcode("http://baidu.com")
    })
上一篇下一篇

猜你喜欢

热点阅读