CanvasRenderingContext2D
.transform()
method of the Canvas 2D API multiplies the current transformation with the matrix described by the arguments of this method. This lets you scale, rotate, translate (move), and skew the context.
注意:
另请参阅
setTransform()
method, which resets the current transform to the identity matrix and then invokes
transform()
.
void ctx.transform(a, b, c, d, e, f);
The transformation matrix is described by:
a
(m11)
1
results in no scaling.
b
(m12)
Vertical skewing.
c
(m21)
Horizontal skewing.
d
(m22)
1
results in no scaling.
e
(dx)
Horizontal translation (moving).
f
(dy)
Vertical translation (moving).
This example skews a rectangle both vertically (
.2
) and horizontally (
.8
). Scaling and translation remain unchanged.
<canvas id="canvas"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.transform(1, .2, .8, 1, 0, 0);
ctx.fillRect(0, 0, 100, 100);
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'CanvasRenderingContext2D.transform' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
transform
|
Chrome Yes | Edge 12 | Firefox 3 | IE Yes | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
CanvasRenderingContext2D
CanvasRenderingContext2D.setTransform()
CanvasRenderingContext2D
addHitRegion()
arc()
arcTo()
beginPath()
bezierCurveTo()
clearHitRegions()
clearRect()
clip()
closePath()
createImageData()
createLinearGradient()
createPattern()
createRadialGradient()
drawFocusIfNeeded()
drawImage()
drawWidgetAsOnScreen()
drawWindow()
ellipse()
fill()
fillRect()
fillText()
getImageData()
getLineDash()
getTransform()
isPointInPath()
isPointInStroke()
lineTo()
measureText()
moveTo()
putImageData()
quadraticCurveTo()
rect()
removeHitRegion()
resetTransform()
restore()
rotate()
save()
scale()
scrollPathIntoView()
setLineDash()
setTransform()
stroke()
strokeRect()
strokeText()
transform()
translate()