canvas scale()
此方法可以對當前繪圖進行縮小或者放大操作。
但是需要注意的是,此方法的實質是對畫布座標系的縮放。
語法結構:
[JavaScript] 純文字檢視 複製程式碼context.scale(scalewidth,scaleheight);
引數解析:
(1).scalewidth:規定座標系x軸方位縮放的比率。
(2).scaleheight:規定座標系y軸方位縮放的比率。
瀏覽器相容:
(1).IE9+瀏覽器支援此方法。
(2).edge瀏覽器支援此方法。
(2).谷歌瀏覽器支援此方法。
(3).火狐瀏覽器支援此方法。
(4).Opera瀏覽器支援此方法。
(5).Safari瀏覽器支援此方法。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> canvas{ border:1px solid black; } </style> <script> window.onload = () => { let cvs=document.getElementById("ant"); let ctx=cvs.getContext("2d"); ctx.strokeRect(5,5,25,15); ctx.scale(4,4); ctx.strokeRect(5,5,25,15); } </script> </head> <body> <canvas id="ant">瀏覽器不支援此標籤</canvas> </body> </html>
程式碼執行效果截圖如下:
程式碼簡單分析如下:
(1).ctx.strokeRect(5,5,25,15),座標系縮放前繪製一個矩形。
(2).ctx.scale(4,4),對座標系整體放大四倍。
(4).ctx.strokeRect(5,5,25,15),因為座標系放大四倍,所以視覺尺寸是原來的四倍。
相關文章
- canvas translate()、scale()和rotate()方法程式碼例項Canvas
- Economies of Scale
- Dealing with Scale in AR
- CSS3 scale(x,y)CSSS3
- Tkinter (16) 拉桿部件 Scale
- VMware vSphere:Optimize and Scale培訓
- 負載均衡的原理(垂直擴充套件 Scale Up、橫向擴充套件 Scale Out)負載套件
- Tkinter (35) 拉桿部件 ttk.Scale
- canvasCanvas
- CSS3 scale3d(x,y,z)CSSS33D
- WPF C# create canvas and draw ellipse in canvasC#Canvas
- Dual Differential Grouping: A More General Decomposition Method for Large-Scale Optimization
- 讀書筆記-增量學習-Large Scale Incremental Learning筆記REM
- tkinter中scale拖拉改變值控制元件(十一)控制元件
- canvas rect()Canvas
- canvas strokeStyleCanvas
- canvas lineTo()Canvas
- canvas strokeRect()Canvas
- canvas createRadialGradient()Canvas
- canvas createLinearGradient()Canvas
- canvas arc()Canvas
- canvas stroke()Canvas
- canvas fill()Canvas
- canvas fillStyleCanvas
- canvas setTransform()CanvasORM
- canvas transform()CanvasORM
- 初探canvasCanvas
- canvas closePath()Canvas
- canvas moveTo()Canvas
- canvas beginPath()Canvas
- canvas getContext()CanvasContext
- canvas getImageData()Canvas
- canvas isPointInPath()Canvas
- canvas putImageData()Canvas
- canvas drawImage()Canvas
- canvas clip()Canvas
- canvas arcTo()Canvas
- canvas createPattern()Canvas