This repository was archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
178 lines (173 loc) · 5.45 KB
/
index.html
File metadata and controls
178 lines (173 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dynamsoft Camera Enhancer Sample - Drawing Shapes</title>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-core@3.0.30/dist/core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-camera-enhancer@4.0.2/dist/dce.js"></script>
</head>
<body>
<select id="select-shapes">
<option value="rect">rectangle</option>
<option value="quad">quadrilateral</option>
<option value="line">line</option>
<option value="text">text</option>
<option value="image">image</option>
</select>
<button id="btn-add-shape">add shape</button>
<button id="btn-remove-all-shapes">remove all shapes</button>
<br />
<button id="btn-use-custom-style">use custom style</button>
<div id="div-ui-container" style="width: 100%; height: 70vh"></div>
<script>
let cameraView, cameraEnhancer;
let drawingLayer;
(async () => {
// Create 'CameraView' instance and use default UI.
cameraView = await Dynamsoft.DCE.CameraView.createInstance();
// Get 'CameraView' instance's UI and append it to DOM.
document
.querySelector("#div-ui-container")
.appendChild(cameraView.getUIElement());
// Create 'CameraEnhancer' instance and pass 'cameraView' to it for UI control.
cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(
cameraView
);
await cameraEnhancer.open();
drawingLayer = cameraView.createDrawingLayer();
})();
document.querySelector("#btn-add-shape").addEventListener("click", () => {
if (!drawingLayer) {
console.error(`The initialization is not complete.`);
return;
}
const shape = document.querySelector("#select-shapes").value;
switch (shape) {
case "rect":
{
const x = 0,
y = 0,
width = 100,
height = 200;
const rectItem = new Dynamsoft.DCE.RectDrawingItem({
x,
y,
width,
height,
});
drawingLayer.addDrawingItems([rectItem]);
}
break;
case "quad":
{
const points = [
{
x: 200,
y: 200,
},
{
x: 400,
y: 150,
},
{
x: 500,
y: 400,
},
{
x: 200,
y: 300,
},
];
const quadItem = new Dynamsoft.DCE.QuadDrawingItem({
points,
});
drawingLayer.addDrawingItems([quadItem]);
}
break;
case "line":
{
const startPoint = { x: 400, y: 100 },
endPoint = { x: 600, y: 300 };
const lineItem = new Dynamsoft.DCE.LineDrawingItem({
startPoint,
endPoint,
});
drawingLayer.addDrawingItems([lineItem]);
}
break;
case "text":
{
const text = "I am a Text.",
x = 700,
y = 100,
width = 200,
height = 100;
const textItem = new Dynamsoft.DCE.TextDrawingItem(
text,
{
x,
y,
width,
height,
}
);
drawingLayer.addDrawingItems([textItem]);
}
break;
case "image":
{
const image = new Image(192, 192),
x = 900,
y = 200,
width = 192,
height = 192;
image.src = "image.png";
image.decode().then(() => {
const imageItem =
new Dynamsoft.DCE.ImageDrawingItem(
image,
{ x, y, width, height },
true
);
drawingLayer.addDrawingItems([imageItem]);
});
}
break;
default:
break;
}
});
document
.querySelector("#btn-remove-all-shapes")
.addEventListener("click", () => {
if (!drawingLayer) {
console.error(`The initialization is not complete.`);
return;
}
drawingLayer.clearDrawingItems();
});
document
.querySelector("#btn-use-custom-style")
.addEventListener("click", () => {
if (!drawingLayer) {
console.error(`The initialization is not complete.`);
return;
}
const styleDefinition = {
lineWidth: 5,
fillStyle: "rgba(254, 180, 32, 0.3)",
strokeStyle: "rgba(254, 180, 32, 0.9)",
paintMode: "strokeAndFill",
fontFamily: "sans-serif",
fontSize: 40,
};
const styleId =
Dynamsoft.DCE.DrawingStyleManager.createDrawingStyle(
styleDefinition
);
drawingLayer.setDefaultStyle(styleId);
});
</script>
</body>
</html>