Skip to content

Commit 02c2bb5

Browse files
committed
需要去除的颜色 模糊
1 parent 8d34dda commit 02c2bb5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

demo2/pickColor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111

112112
function getColor() {
113113
RGBaster.colors(imgDom, {
114-
exclude: [],
114+
exclude: ['255,255,255'],//需要去除的颜色 模糊(不提供时会主动提取背景色!)
115115
success: function (payload) {
116116
// payload.dominant是主色,RGB形式表示
117117
// payload.secondary是次色,RGB形式表示

demo2/rgbaster.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@
160160
dominant: {name: '', count: 0},
161161
palette: []
162162
};
163-
let _backColorRangeArr = backColorRange(fmtImgData(data)).name.split(',');
163+
//获取 图片背景色
164+
let _backColorRangeArr = exclude.length ? exclude : [backColorRange(fmtImgData(data)).name];
164165
let _bias = RGBaster.backColorRange.bias;
165166
var i = 0;
166167
for (; i < data.length; i += 4) {
@@ -176,12 +177,21 @@
176177
}
177178

178179
//skip background color range
179-
if ((Math.abs(_backColorRangeArr[0] - data[i]) < _bias && Math.abs(_backColorRangeArr[1] - data[i + 1]) < _bias && Math.abs(_backColorRangeArr[2] - data[i + 2]) < _bias)) {
180-
// console.log(rgbString)
181-
continue;
180+
let isBackColorRangeFlag = false;
181+
for (let color of _backColorRangeArr) {
182+
let _color = color.split(',');
183+
if ((Math.abs(_color[0] - data[i]) < _bias && Math.abs(_color[1] - data[i + 1]) < _bias && Math.abs(_color[2] - data[i + 2]) < _bias)) {
184+
// console.log(rgbString)
185+
isBackColorRangeFlag = true;
186+
break;
187+
}
188+
}
189+
if(isBackColorRangeFlag){
190+
continue;
182191
}
192+
183193
// Ignore those colors in the exclude list.
184-
if (exclude.indexOf(makeRGB(rgbString)) === -1) {
194+
if (exclude.indexOf(rgbString) === -1) {
185195
//计数
186196
if (rgbString in colorCounts) {
187197
colorCounts[rgbString] = colorCounts[rgbString] + 1;

0 commit comments

Comments
 (0)