-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-data-png.html
43 lines (40 loc) · 1.43 KB
/
import-data-png.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>导入数据图片</title>
</head>
<body>
<script>
var source = './data/fututhreeyear-data-year.png';
//导入逻辑
var img = document.createElement('img');
img.onload = function(){
var canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
var context = canvas.getContext("2d");
context.drawImage(img, 0, 0);
var imageData = context.getImageData(0, 0, canvas.width, canvas.height),
pixels = imageData.data;
var script = document.createElement('script');
var buffer = [];
for (var i = 0, l = pixels.length; i < l; i++) {
if (i % 4 == 3) continue; // alpha会影响png还原
if (!pixels[i]) break;
buffer.push(String.fromCharCode(pixels[i]));
}
script.src = 'data:text/javascript;charset=utf-8,' + encodeURIComponent(buffer.join(''));
document.body.appendChild(script);
script.onload = function(){
//输出数据看看是否一致
console.log(yearPosition);
console.log(yearDiffHeight);
console.log(yearFillLength);
}
img = null;
}
img.src = source;
</script>
</body>
</html>