IT/- 프로그래밍
HTML5/CSS3 canvas 클리핑(오려내기)
혁준7519
2017. 7. 15. 13:06
canvas 클리핑(오려내기)
html)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, height=device-height, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0"> <title>Insert title here</title> <script type="text/javascript"> window.onload = function(){ var canvas = document.getElementById("canvas"); if(canvas.getContext){ var draw = canvas.getContext("2d"); draw.beginPath(); draw.arc(150, 150, 100, 0, Math.PI*2, true); draw.lineWidth = 5; draw.stroke(); //clip : 그린 도형 만큼 잘라내서 보여준다 draw.clip(); var img = new Image(); img.src = "images/testimage.jpg"; img.onload = function(){ draw.drawImage(img, 50, 50, 250, 250); } } } </script> </head> <body> <canvas id="canvas" width="300px" height="400px"></canvas> </body> </html> | cs |
결과