再调整对比色算法

This commit is contained in:
walker 2023-09-01 17:12:26 +08:00
parent 1762d6e629
commit cc737578ba

View File

@ -101,13 +101,26 @@ export class CommonMouseTool extends AppInteractionPlugin {
return new CommonMouseTool(app); return new CommonMouseTool(app);
} }
/**
*
* @param rgb
* @returns
*/
private calContrastColor(rgb: number): number {
if (rgb > 0.45 && rgb < 0.55) {
return 0;
} else {
return 1 - rgb;
}
}
private updateBoxLineColor(cp: ICanvasProperties) { private updateBoxLineColor(cp: ICanvasProperties) {
// 根据画布背景调整线色 // 根据画布背景调整线色
const color = new Color(cp.backgroundColor); const color = new Color(cp.backgroundColor);
// 对比色 // 对比色
const r = 1 - color.red; const r = this.calContrastColor(color.red);
const g = 1 - color.green; const g = this.calContrastColor(color.green);
const b = 1 - color.blue; const b = this.calContrastColor(color.blue);
this._boxLineColor.setValue([r, g, b]); this._boxLineColor.setValue([r, g, b]);
} }