Skip to content

Commit 2e64872

Browse files
committed
取消获取背景色功能
1 parent a0f84d2 commit 2e64872

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

src/utils/tools.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@ function copyToClip (content) {
1616
* @param {String} dataURI
1717
* @returns {Promise}
1818
*/
19-
function getImgMainColor (dataURL) {
20-
const img = new Image()
21-
img.src = dataURL
22-
return new Promise((resolve) => {
23-
img.onload = () => {
24-
const canvas = document.createElement('canvas')
25-
const ctx = canvas.getContext('2d')
26-
ctx.drawImage(img, 0, 0, 150, 150)
27-
const data = ctx.getImageData(0, 0, 150, 150).data
28-
const colorList = data.reduce((accumulator, _, index) => {
29-
if (index % 4 === 0 && data[index + 3] !== 0) {
30-
let rgb = `${data[index]},${data[index + 1]},${data[index + 2]}`
31-
accumulator[rgb] = (accumulator[rgb] + 1) || 1
32-
}
33-
return accumulator
34-
}, {})
35-
let maxKey = ''
36-
let maxVal = 0
37-
for (let key in colorList) {
38-
if (colorList[key] > maxVal) {
39-
maxVal = colorList[key]
40-
maxKey = key
41-
}
42-
}
43-
resolve(maxKey)
44-
}
45-
})
46-
}
19+
// function getImgMainColor (dataURL) {
20+
// const img = new Image()
21+
// img.src = dataURL
22+
// return new Promise((resolve) => {
23+
// img.onload = () => {
24+
// const canvas = document.createElement('canvas')
25+
// const ctx = canvas.getContext('2d')
26+
// ctx.drawImage(img, 0, 0, 150, 150)
27+
// const data = ctx.getImageData(0, 0, 150, 150).data
28+
// const colorList = data.reduce((accumulator, _, index) => {
29+
// if (index % 4 === 0 && data[index + 3] !== 0) {
30+
// let rgb = `${data[index]},${data[index + 1]},${data[index + 2]}`
31+
// accumulator[rgb] = (accumulator[rgb] + 1) || 1
32+
// }
33+
// return accumulator
34+
// }, {})
35+
// let maxKey = ''
36+
// let maxVal = 0
37+
// for (let key in colorList) {
38+
// if (colorList[key] > maxVal) {
39+
// maxVal = colorList[key]
40+
// maxKey = key
41+
// }
42+
// }
43+
// resolve(maxKey)
44+
// }
45+
// })
46+
// }
4747

4848
/**
4949
* 防抖函数
@@ -159,7 +159,6 @@ function isProd () {
159159

160160
export {
161161
copyToClip,
162-
getImgMainColor,
163162
debounce,
164163
throttle,
165164
escapeRegExp,

0 commit comments

Comments
 (0)