課程
/前端開發(fā)
/Html5
/Canvas玩轉(zhuǎn)圖像處理
老師,我想通過A坐標和B坐標,再一個寬度的矩形用canvas應(yīng)該怎么繪制
2020-09-04
源自:Canvas玩轉(zhuǎn)圖像處理 4-4
正在回答
<body>??<canvas?id="canvas"?width="800"?height="800"></canvas>??<div?style="margin-top:?10px;">????aX:?<input?id="aX"?type="text"?value="100">????aY:?<input?id="aY"?type="text"?value="100">????<br>????bX:?<input?id="bX"?type="text"?value="300">????bY:?<input?id="bY"?type="text"?value="300">????<br>????width:?<input?id="width"?type="text"?value="200">????<button?onclick="drawRect()">創(chuàng)建矩形</button>??</div>??<script>????const?canvas?=?document.getElementById('canvas');????const?cxt?=?canvas.getContext('2d');????window.onload?=?function()?{??????drawRect();????}????function?drawRect()?{??????let?aX?=?document.getElementById('aX').value;??????let?aY?=?document.getElementById('aY').value;??????let?bX?=?document.getElementById('bX').value;??????let?bY?=?document.getElementById('bY').value;??????let?width?=?document.getElementById('width').value;??????let?noValue?=?!aX?||?!aY?||?!bX?||?!bY?||?!width;??????if(noValue)?{????????alert('請把數(shù)據(jù)填全!');????????return;??????}??????//?畫矩形??????cxt.clearRect(0,?0,?canvas.width,?canvas.height);??????cxt.beginPath();??????cxt.moveTo(aX,?aY);??????cxt.lineTo(bX,?bY);??????cxt.lineWidth?=?width;??????cxt.stroke();????}??</script></body>
我自己寫了一個,不知道是不是你想要的效果
舉報
canvas系列第三課,學會編寫圖像算法,一起玩轉(zhuǎn)圖像處理吧
1 回答老師,從相冊中選擇圖片,用canvas畫圖,方向會反,怎么辦
2 回答關(guān)于canvas畫圖
3 回答圖像形狀處理
2 回答canvas圖像適應(yīng)分辨率并且保證圖片不變形
1 回答圖片點坐標問題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2020-12-14
我自己寫了一個,不知道是不是你想要的效果