-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblend-two.html
74 lines (63 loc) · 1.75 KB
/
blend-two.html
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
canvas {
float: left;
width: 320px;
height: 480px;
}
</style>
</head>
<body>
<script src="filter-blend.js"></script>
<script>
(function () {
function Canvas() {
var canvas = document.createElement( "canvas" );
canvas.width = 320;
canvas.height = 480;
return canvas;
}
// 并发
function concurrentTask( tasks, callback ) {
var len = tasks.length,
count = 0;
tasks.forEach( function ( task ) {
task( function () {
count++;
if ( count == len ) {
callback();
}
} );
} );
}
var img1, img2;
concurrentTask( [
function ( done ) {
img1 = new Image();
img1.src = "img/h.jpg";
img1.onload = done;
},
function ( done ) {
img2 = new Image();
img2.src = "img/h5.jpg";
img2.onload = done;
}
], function () {
var canvas = Canvas();
var gc = canvas.getContext( "2d" );
document.body.appendChild( canvas );
var canvas2 = Canvas();
var gc2 = canvas2.getContext( "2d" );
gc.drawImage( img1, 0, 0 );
gc2.drawImage( img2, 0, 0 );
var data = blend( gc2.getImageData( 0, 0, 320, 480 ), gc.getImageData( 0, 0, 320, 480 ), "overlap" );
gc.putImageData( data, 0, 0 );
} );
})();
</script>
</body>
</html>