mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
增加文字颜色与背景颜色色差设置
This commit is contained in:
parent
d730347399
commit
57d9a415fc
@ -18,6 +18,7 @@
|
|||||||
* 【http 】 CompressUtil.createExtractor支持tgz自动识别(pr#3674@Github)
|
* 【http 】 CompressUtil.createExtractor支持tgz自动识别(pr#3674@Github)
|
||||||
* 【poi 】 ExcelWriter.autoSizeColumn增加可选widthRatio参数,可配置中文字符宽度倍数(pr#3689@Github)
|
* 【poi 】 ExcelWriter.autoSizeColumn增加可选widthRatio参数,可配置中文字符宽度倍数(pr#3689@Github)
|
||||||
* 【mail 】 MailAccount增加自定义参数支持(issue#3687@Github)
|
* 【mail 】 MailAccount增加自定义参数支持(issue#3687@Github)
|
||||||
|
* 【mail 】 增加文字颜色与背景颜色色差设置(pr#1252@gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复因RFC3986理解有误导致的UrlPath处理冒号转义问题(issue#IAAE88@Gitee)
|
* 【core 】 修复因RFC3986理解有误导致的UrlPath处理冒号转义问题(issue#IAAE88@Gitee)
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package cn.hutool.captcha;
|
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.GraphicsUtil;
|
||||||
import cn.hutool.core.img.ImgUtil;
|
import cn.hutool.core.img.ImgUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
@ -9,7 +7,10 @@ import cn.hutool.core.util.RandomUtil;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
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.awt.image.BufferedImage;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ public class CaptchaUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class TestLineCaptcha extends AbstractCaptcha{
|
static class TestLineCaptcha extends AbstractCaptcha{
|
||||||
|
private static final long serialVersionUID = -558846929114465692L;
|
||||||
|
|
||||||
public TestLineCaptcha(int width, int height, int codeCount, int interfereCount) {
|
public TestLineCaptcha(int width, int height, int codeCount, int interfereCount) {
|
||||||
super(width, height, codeCount, interfereCount);
|
super(width, height, codeCount, interfereCount);
|
||||||
|
@ -169,16 +169,6 @@ public class ColorUtil {
|
|||||||
return new Color(r, g, b);
|
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
|
* @since 5.8.30
|
||||||
*/
|
*/
|
||||||
public static Color randomColor(Color compareColor,int minDistance) {
|
public static Color randomColor(Color compareColor,int minDistance) {
|
||||||
Color color = randomColor(null);
|
Color color = randomColor();
|
||||||
while (computeColorDistance(compareColor,color) < minDistance) {
|
while (computeColorDistance(compareColor,color) < minDistance) {
|
||||||
color = randomColor(null);
|
color = randomColor();
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成随机颜色
|
||||||
|
*
|
||||||
|
* @return 随机颜色
|
||||||
|
* @since 3.1.2
|
||||||
|
*/
|
||||||
|
public static Color randomColor() {
|
||||||
|
return randomColor(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算两个颜色之间的色差,按三维坐标距离计算
|
* 计算两个颜色之间的色差,按三维坐标距离计算
|
||||||
*
|
*
|
||||||
@ -283,7 +283,7 @@ public class ColorUtil {
|
|||||||
* @return 是否匹配
|
* @return 是否匹配
|
||||||
*/
|
*/
|
||||||
private static boolean matchFilters(int r, int g, int b, int[]... rgbFilters) {
|
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) {
|
for (int[] rgbFilter : rgbFilters) {
|
||||||
if (r == rgbFilter[0] && g == rgbFilter[1] && b == rgbFilter[2]) {
|
if (r == rgbFilter[0] && g == rgbFilter[1] && b == rgbFilter[2]) {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user