码迷,mamicode.com
首页 > Web开发 > 详细

js 图片base64

时间:2016-06-08 18:46:44      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <script>
        function init() {
            var canvas = document.createElement(‘canvas‘)
            var ctx = canvas.getContext(‘2d‘);
            var img = new Image();
            img.src = "临时图片/1.png";
            img.onload = function() {
                //原图的大小
                ctx.drawImage(img, 0, 0, 100, 100);
                console.log(canvas.toDataURL())
                document.getElementById(‘imgbase64‘).src = canvas.toDataURL();
            }
        }
    </script>
</head>

<body onload="init()">
    <img id="imgbase64" src="" />
</body>

</html>

 

js 图片base64

标签:

原文地址:http://www.cnblogs.com/zhaojia-dream/p/5570761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!