質問編集履歴
2
fさふぁ
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
border: 'solid 1px #000',
|
16
16
|
|
17
|
-
'background-color':
|
17
|
+
'background-color': #ff0000
|
18
18
|
|
19
19
|
}"
|
20
20
|
|
1
fa
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
【
|
1
|
+
【Nuxt.js】canvasを画像化する際にバックグランドカラーが表示されない【Javascript】
|
test
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
`png`形式にすると背景が透明色で保存され、`jpeg`で保存すると背景色が真っ黒で表示されます。
|
4
4
|
|
5
5
|
```html
|
6
|
+
|
7
|
+
<template>
|
6
8
|
|
7
9
|
<canvas
|
8
10
|
|
@@ -12,13 +14,69 @@
|
|
12
14
|
|
13
15
|
border: 'solid 1px #000',
|
14
16
|
|
15
|
-
'background-color':
|
17
|
+
'background-color': this.selectedTemplate.background,
|
16
18
|
|
17
19
|
}"
|
18
20
|
|
19
21
|
>
|
20
22
|
|
21
23
|
</canvas>
|
24
|
+
|
25
|
+
</template>
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
//描画処理
|
30
|
+
|
31
|
+
<script>
|
32
|
+
|
33
|
+
export default {
|
34
|
+
|
35
|
+
mounted() {
|
36
|
+
|
37
|
+
this.ctx = document.getElementById('preview').getContext('2d')
|
38
|
+
|
39
|
+
this.drawCreative()
|
40
|
+
|
41
|
+
},
|
42
|
+
|
43
|
+
methods: {
|
44
|
+
|
45
|
+
drawCreative() {
|
46
|
+
|
47
|
+
this.ctx.canvas.width = 500
|
48
|
+
|
49
|
+
this.ctx.canvas.height = 500
|
50
|
+
|
51
|
+
this.ctx.beginPath()
|
52
|
+
|
53
|
+
this.ctx.clearRect(0, 0, 500, 500)
|
54
|
+
|
55
|
+
this.ctx.fill()
|
56
|
+
|
57
|
+
},
|
58
|
+
|
59
|
+
downloadCanvas() {
|
60
|
+
|
61
|
+
const canvasImage = document.getElementById('preview')
|
62
|
+
|
63
|
+
const link = document.createElement('a')
|
64
|
+
|
65
|
+
link.href = canvasImage.toDataURL('image/png')
|
66
|
+
|
67
|
+
link.download = 'hoge.png'
|
68
|
+
|
69
|
+
link.click()
|
70
|
+
|
71
|
+
},
|
72
|
+
|
73
|
+
},
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
</script>
|
78
|
+
|
79
|
+
|
22
80
|
|
23
81
|
```
|
24
82
|
|