日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

canvas 绘图

發布時間:2024/9/21 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 canvas 绘图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

canvas

<canvas id="drawing" width="200" height="200">xxx</canvas> <script>var drawing = document.getElementById('drawing')//傳入 2d 就可以獲得 2D 上下文drawing.getContent('2d')//保存圖片,添加到頁面中var imgURL = drawing.toDataURL('image/png')var img = document.createElement('img')img.src = imgURLdocument.body.appendChild(img)//矩形填充context.fillStyle = '#0000ff'context.fillRect(10,10,50,50)//矩形描邊context.strokeStyle = 'red';context.strokeRect(10,60,50,50)//清除矩形context.clearRect(20,20,10,10)//保存和調用上下文ctx.fillStyle='#ff0000'ctx.save()ctx.fillStyle='#00ff00'ctx.translate(100,100)ctx.save()ctx.fillStyle='#000000'ctx.translate(200,200)ctx.save()ctx.fillStyle='#0000ff'ctx.fillRect(0,0,100,200)ctx.restore()ctx.fillRect(10,10,100,200)ctx.restore()ctx.fillRect(0,0,100,200)ctx.restore()ctx.fillRect(20,20,100,200)</script>

canvas必須先設置width和height

  • getContext("2d")傳入 2d 就可以獲得 2D 上下文
  • toDataURL('image/png')可以把canvas畫的圖片保存下來,默認格式為png,也可設置為jpeg
  • fillRect(x,y,width,height)填充矩形,fillStyle填充顏色
  • strokeRect(x,y,width,height)描邊矩形,strokeStyle描邊顏色
  • lineWidth設置線條寬度
  • lineCap設置線條末尾的形狀,取值:butt平頭,round圓頭,square方頭
  • lineJoin設置線條相交方式,取值:round圓交,bevel斜交,miter斜接
  • clearRect(x,y,width.height)清除矩形
  • translate(x,y)變換原點坐標,將原點坐標移動到(x,y)
  • rotate()圍繞原點旋轉
  • save()保存上下,只保存上下文的設置和變換,不會保存上下文的內容
  • restore()調用上下文,調用從最近一個save()開始調用,逐級往上。
  • drawImage(繪制的圖像,源圖像x,源圖像y,源圖像width,源圖像height,目標圖像x,目標圖像y,目標圖像width,目標圖像height)
  • globalAlpha設置全局透明度
  • 總結

    以上是生活随笔為你收集整理的canvas 绘图的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。