回答編集履歴
1
追記
test
CHANGED
@@ -5,3 +5,63 @@
|
|
5
5
|
```
|
6
6
|
|
7
7
|
で複製したらどうですか?
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
(追記)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
わかりました。drawImageできるイメージが欲しいわけですね(質問にそう書いてますね)
|
20
|
+
|
21
|
+
canvas要素の複製は不要ですね。
|
22
|
+
|
23
|
+
これでどうでしょう。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
<canvas id="canvas" width="200" height="200" style="background-color: black;"></canvas>
|
30
|
+
|
31
|
+
<canvas id="another-canvas" width="500" height="500" style="background-color: black;"></canvas>
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
<script>
|
36
|
+
|
37
|
+
const canvas = document.getElementById('canvas');
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
// canvasに適当に描画
|
42
|
+
|
43
|
+
const ctx = canvas.getContext('2d');
|
44
|
+
|
45
|
+
ctx.fillStyle = "green";
|
46
|
+
|
47
|
+
ctx.fillRect(50, 50, 50, 50);
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
// canvasに描画された内容をPNGデータ化して仮のimg要素に指定
|
52
|
+
|
53
|
+
const image = document.createElement("img");
|
54
|
+
|
55
|
+
image.src = canvas.toDataURL();
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
// another-canvasにdrawImage
|
60
|
+
|
61
|
+
const anotherCanvas = document.getElementById('another-canvas');
|
62
|
+
|
63
|
+
anotherCanvas.getContext('2d').drawImage(image, 0, 0, anotherCanvas.width, anotherCanvas.height);
|
64
|
+
|
65
|
+
</script>
|
66
|
+
|
67
|
+
```
|