代码
提交代码
<canvas id="test" width="500" height="500">您的浏览器不支持canvas</canvas> <script> var canvas = document.getElementById("test"); canvas.width = 800; canvas.height = 600; var context = canvas.getContext("2d"); var img = new Image(); img.src = "https://www.easyicon.net/api/resizeApi.php?id=1183257&size=16"; img.onload = function(){ var pattern = context.createPattern(img, "repeat"); context.fillStyle = pattern; context.fillRect(0,0,500,400); } </script>
运行结果