From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/canvasrenderingcontext2d/save/index.html | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 files/ja/web/api/canvasrenderingcontext2d/save/index.html (limited to 'files/ja/web/api/canvasrenderingcontext2d/save') diff --git a/files/ja/web/api/canvasrenderingcontext2d/save/index.html b/files/ja/web/api/canvasrenderingcontext2d/save/index.html new file mode 100644 index 0000000000..e12c603823 --- /dev/null +++ b/files/ja/web/api/canvasrenderingcontext2d/save/index.html @@ -0,0 +1,91 @@ +--- +title: CanvasRenderingContext2D.save() +slug: Web/API/CanvasRenderingContext2D/save +tags: + - API + - Canvas + - CanvasRenderingContext2D + - Method + - Reference +translation_of: Web/API/CanvasRenderingContext2D/save +--- +
{{APIRef}}
+ +

Canvas 2D API の CanvasRenderingContext2D.save() メソッドは、現在の状態をプッシュしてキャンバスの全体の状態をスタックに保存します。

+ +

描画状態

+ +

スタックに保存される描画状態には以下のものが含まれます:

+ + + +

構文

+ +
void ctx.save();
+ +

+ +

描画状態を保存する

+ +

この例は、save() メソッドを使用してデフォルトの状態を保存して、restore() を使用して復元しているため、デフォルトの状態で長方形を描画できます。

+ +

HTML

+ +
<canvas id="canvas"></canvas>
+
+ +

JavaScript

+ +
const canvas = document.getElementById('canvas');
+const ctx = canvas.getContext('2d');
+
+// Save the default state
+ctx.save();
+
+ctx.fillStyle = 'green';
+ctx.fillRect(10, 10, 100, 100);
+
+// Restore the default state
+ctx.restore();
+
+ctx.fillRect(150, 40, 100, 100);
+
+ +

結果

+ +

{{ EmbedLiveSample('Saving_the_drawing_state', 700, 180) }}

+ +

仕様

+ + + + + + + + + + + + + + +
仕様状態コメント
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-save", "CanvasRenderingContext2D.save")}}{{Spec2('HTML WHATWG')}}
+ +

ブラウザー実装状況

+ + + +

{{Compat("api.CanvasRenderingContext2D.save")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf