mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
AbstractCaptcha增加setStroke方法支持线条粗细(issue#IDJQ15@Gitee)
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
# 5.8.44(2026-01-12)
|
# 5.8.44(2026-01-12)
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 `NumberUtil.parseNumber`增加支持科学计数法(pr#4211@Github)
|
* 【core 】 `NumberUtil.parseNumber`增加支持科学计数法(pr#4211@Github)
|
||||||
|
* 【captcha】 `AbstractCaptcha`增加`setStroke`方法支持线条粗细(issue#IDJQ15@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【json 】 修复`JSONUtil.wrap`忽略错误问题(issue#4210@Github)
|
* 【json 】 修复`JSONUtil.wrap`忽略错误问题(issue#4210@Github)
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ import cn.hutool.core.io.IORuntimeException;
|
|||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.URLUtil;
|
import cn.hutool.core.util.URLUtil;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
import java.awt.*;
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -65,6 +62,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
|
|||||||
* 文字透明度
|
* 文字透明度
|
||||||
*/
|
*/
|
||||||
protected AlphaComposite textAlpha;
|
protected AlphaComposite textAlpha;
|
||||||
|
protected Stroke stroke;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造,使用随机验证码生成器生成验证码
|
* 构造,使用随机验证码生成器生成验证码
|
||||||
@@ -271,4 +269,13 @@ public abstract class AbstractCaptcha implements ICaptcha {
|
|||||||
this.textAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, textAlpha);
|
this.textAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, textAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置画笔线条特征,如线条宽度等
|
||||||
|
*
|
||||||
|
* @param stroke 画笔
|
||||||
|
* @since 5.8.44
|
||||||
|
*/
|
||||||
|
public void setStroke(Stroke stroke) {
|
||||||
|
this.stroke = stroke;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,11 @@ public class CircleCaptcha extends AbstractCaptcha {
|
|||||||
* @param g {@link Graphics2D}
|
* @param g {@link Graphics2D}
|
||||||
*/
|
*/
|
||||||
private void drawInterfere(Graphics2D g) {
|
private void drawInterfere(Graphics2D g) {
|
||||||
|
// issue#IDJQ15 自定义线条特征(粗细等)
|
||||||
|
if(null != this.stroke){
|
||||||
|
g.setStroke(this.stroke);
|
||||||
|
}
|
||||||
|
|
||||||
final ThreadLocalRandom random = RandomUtil.getRandom();
|
final ThreadLocalRandom random = RandomUtil.getRandom();
|
||||||
|
|
||||||
for (int i = 0; i < this.interfereCount; i++) {
|
for (int i = 0; i < this.interfereCount; i++) {
|
||||||
|
|||||||
@@ -110,6 +110,11 @@ public class LineCaptcha extends AbstractCaptcha {
|
|||||||
* @param g {@link Graphics2D}画笔
|
* @param g {@link Graphics2D}画笔
|
||||||
*/
|
*/
|
||||||
private void drawInterfere(Graphics2D g) {
|
private void drawInterfere(Graphics2D g) {
|
||||||
|
// issue#IDJQ15 自定义线条特征(粗细等)
|
||||||
|
if(null != this.stroke){
|
||||||
|
g.setStroke(this.stroke);
|
||||||
|
}
|
||||||
|
|
||||||
final ThreadLocalRandom random = RandomUtil.getRandom();
|
final ThreadLocalRandom random = RandomUtil.getRandom();
|
||||||
// 干扰线
|
// 干扰线
|
||||||
for (int i = 0; i < this.interfereCount; i++) {
|
for (int i = 0; i < this.interfereCount; i++) {
|
||||||
|
|||||||
@@ -193,7 +193,6 @@ public class ShearCaptcha extends AbstractCaptcha {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("SameParameterValue")
|
@SuppressWarnings("SameParameterValue")
|
||||||
private void drawInterfere(Graphics g, int x1, int y1, int x2, int y2, int thickness, Color c) {
|
private void drawInterfere(Graphics g, int x1, int y1, int x2, int y2, int thickness, Color c) {
|
||||||
|
|
||||||
// The thick line is in fact a filled polygon
|
// The thick line is in fact a filled polygon
|
||||||
g.setColor(c);
|
g.setColor(c);
|
||||||
int dX = x2 - x1;
|
int dX = x2 - x1;
|
||||||
|
|||||||
Reference in New Issue
Block a user