CanvasPattern: setTransform() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
CanvasPattern.setTransform()
メソッドは、パターンの変換行列として DOMMatrix
オブジェクトを使用し、パターンにこれを実行します。
構文
js
setTransform(matrix)
引数
返値
なし (undefined
)。
例
setTransform
メソッドの使用
これは setTransform
メソッドを使用して DOMMatrix
によるパターンの座標変換を指定して CanvasPattern
を生成する簡単なコードスニペットです。たとえば、パターンが現在の fillStyle
として適用され、fillRect()
メソッドを使用すると、キャンバスに描画されます。
HTML
html
<canvas id="canvas"></canvas>
JavaScript
js
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const matrix = new DOMMatrix([1, 0.2, 0.8, 1, 0, 0]);
const img = new Image();
img.src =
"/en-US/docs/Web/API/CanvasPattern/setTransform/canvas_createpattern.png";
img.onload = () => {
const pattern = ctx.createPattern(img, "repeat");
pattern.setTransform(matrix.rotate(-45).scale(1.5));
ctx.fillStyle = pattern;
ctx.fillRect(0, 0, 400, 400);
};
編集可能なデモ
上のコードスニペットの編集可能なデモです。 SetTransform()
の引数を変更して、その効果を確認してみてください。
仕様書
Specification |
---|
HTML # dom-canvaspattern-settransform-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
setTransform | ||||||||||||
Accepts a DOMMatrix2DInit -like object parameter |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
関連情報
- このメソッドを定義しているインターフェイス:
CanvasPattern
DOMMatrix