增加文字颜色与背景颜色色差设置

This commit is contained in:
Looly 2024-08-08 16:32:37 +08:00
parent d730347399
commit 57d9a415fc
3 changed files with 19 additions and 16 deletions

View File

@ -18,6 +18,7 @@
* 【http 】 CompressUtil.createExtractor支持tgz自动识别pr#3674@Github
* 【poi 】 ExcelWriter.autoSizeColumn增加可选widthRatio参数可配置中文字符宽度倍数pr#3689@Github
* 【mail 】 MailAccount增加自定义参数支持issue#3687@Github
* 【mail 】 增加文字颜色与背景颜色色差设置pr#1252@gitee
### 🐞Bug修复
* 【core 】 修复因RFC3986理解有误导致的UrlPath处理冒号转义问题issue#IAAE88@Gitee

View File

@ -1,7 +1,5 @@
package cn.hutool.captcha;
import cn.hutool.captcha.generator.CodeGenerator;
import cn.hutool.captcha.generator.MathGenerator;
import cn.hutool.core.img.GraphicsUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.util.ObjectUtil;
@ -9,7 +7,10 @@ import cn.hutool.core.util.RandomUtil;
import org.junit.Ignore;
import org.junit.Test;
import java.awt.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.concurrent.ThreadLocalRandom;
@ -33,6 +34,7 @@ public class CaptchaUtilTest {
}
static class TestLineCaptcha extends AbstractCaptcha{
private static final long serialVersionUID = -558846929114465692L;
public TestLineCaptcha(int width, int height, int codeCount, int interfereCount) {
super(width, height, codeCount, interfereCount);

View File

@ -169,16 +169,6 @@ public class ColorUtil {
return new Color(r, g, b);
}
/**
* 生成随机颜色
*
* @return 随机颜色
* @since 3.1.2
*/
public static Color randomColor() {
return randomColor(null);
}
/**
* 生成随机颜色与指定颜色有一定的区分度
*
@ -188,13 +178,23 @@ public class ColorUtil {
* @since 5.8.30
*/
public static Color randomColor(Color compareColor,int minDistance) {
Color color = randomColor(null);
Color color = randomColor();
while (computeColorDistance(compareColor,color) < minDistance) {
color = randomColor(null);
color = randomColor();
}
return color;
}
/**
* 生成随机颜色
*
* @return 随机颜色
* @since 3.1.2
*/
public static Color randomColor() {
return randomColor(null);
}
/**
* 计算两个颜色之间的色差按三维坐标距离计算
*
@ -283,7 +283,7 @@ public class ColorUtil {
* @return 是否匹配
*/
private static boolean matchFilters(int r, int g, int b, int[]... rgbFilters) {
if (rgbFilters != null && rgbFilters.length > 0) {
if (ArrayUtil.isNotEmpty(rgbFilters)) {
for (int[] rgbFilter : rgbFilters) {
if (r == rgbFilter[0] && g == rgbFilter[1] && b == rgbFilter[2]) {
return true;