js HTML5 canvas繪制圖片的方法
來源:懂視網(wǎng)
責編:小OO
時間:2020-11-27 22:30:48
js HTML5 canvas繪制圖片的方法
本文實例為大家分享了HTML5 canvas繪制圖片的具體代碼,供大家參考,具體內(nèi)容如下:demo.js;window.onload=function() { createcanvas();drawImage();} function createcanvas() { var CANVAS=document.getElementById('mycanvas');context=CANVAS.getContext('2d');} function drawImage() { var img=new Image();img.onload=function() { context.drawImage(img,0,0,200,200 );} img.src="img5.jpg";}。
導讀本文實例為大家分享了HTML5 canvas繪制圖片的具體代碼,供大家參考,具體內(nèi)容如下:demo.js;window.onload=function() { createcanvas();drawImage();} function createcanvas() { var CANVAS=document.getElementById('mycanvas');context=CANVAS.getContext('2d');} function drawImage() { var img=new Image();img.onload=function() { context.drawImage(img,0,0,200,200 );} img.src="img5.jpg";}。
本文實例為大家分享了HTML5 canvas繪制圖片的具體代碼,供大家參考,具體內(nèi)容如下
demo.js
window.onload=function() {
createcanvas();
drawImage();
}
function createcanvas() {
var CANVAS=document.getElementById('mycanvas');
context=CANVAS.getContext('2d');
}
function drawImage() {
var img=new Image();
img.onload=function() {
context.drawImage(img,0,0,200,200 );
}
img.src="img5.jpg";
}
demo.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>canvas</title>
<script type="text/javascript" src="demo.js"></script>
</head>
<body>
<canvas id="mycanvas" width="400" hight="400" >
<span>你的瀏覽器不支持canvas</span>
</canvas>
</body>
</html>
圖片:
效果:
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
js HTML5 canvas繪制圖片的方法
本文實例為大家分享了HTML5 canvas繪制圖片的具體代碼,供大家參考,具體內(nèi)容如下:demo.js;window.onload=function() { createcanvas();drawImage();} function createcanvas() { var CANVAS=document.getElementById('mycanvas');context=CANVAS.getContext('2d');} function drawImage() { var img=new Image();img.onload=function() { context.drawImage(img,0,0,200,200 );} img.src="img5.jpg";}。