OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <style> | |
3 svg { | |
4 display: none; | |
5 } | |
6 canvas { | |
7 border: 1px solid black; | |
8 } | |
9 </style> | |
10 | |
11 <svg id="s1" width="200px" height="20px"> | |
12 <image id="img1" href="resources/pattern.png" x="0" y="0" width="20px" height=
"20px" /> | |
13 <image id="img2" href="resources/pattern.png" x="20" y="0" width="40px" height
="40px" /> | |
14 <image id="img3" href="resources/pattern.png" x="40" y="0" width="40px" height
="40px" /> | |
15 <image id="img4" href="invalid" x="60" y="0" width="20px" height="20px" /> | |
16 <image id="img5" href="resources/pattern.png" x="80" y="0" width="20px" height
="20px" /> | |
17 </svg> | |
18 | |
19 <canvas id="c1" width="20" height="20"></canvas> | |
20 <canvas id="c2" width="20" height="20"></canvas> | |
21 <canvas id="c3" width="20" height="20"></canvas> | |
22 <canvas id="c4" width="20" height="20"></canvas> | |
23 <canvas id="c5" width="20" height="20"></canvas> | |
24 <canvas id="c6" width="20" height="20"></canvas> | |
25 | |
26 <script> | |
27 var draw = function(target, img, x, y, opts) { | |
28 document.getElementById(img).addEventListener("load", function() { | |
29 createImageBitmap(this, opts).then((ib) => { | |
30 document.getElementById(target).getContext("2d").drawImage( | |
31 ib, x || 0, y || 0); | |
32 }); | |
33 }); | |
34 } | |
35 | |
36 draw("c1", "img1"); | |
37 draw("c2", "img2", 10, 10); | |
38 draw("c3", "img3"); | |
39 draw("c4", "img4"); | |
40 document.getElementById("c5").getContext("2d").drawImage( | |
41 document.getElementById("img5"), 0, 0); | |
42 draw("c6", "img2", 0, 0, {resizeWidth: 10, resizeHeight: 10}); | |
43 | |
44 </script> | |
OLD | NEW |