This commit is contained in:
Looly 2024-08-08 17:05:09 +08:00
parent b5cba1db65
commit 67463d5dc4
2 changed files with 9 additions and 4 deletions

View File

@ -132,7 +132,7 @@ public class GifCaptcha extends AbstractCaptcha {
}
/**
* 设置验证码字符颜色
* 设置验证码字符最大取色范围
*
* @param maxColor 颜色
* @return this
@ -143,7 +143,7 @@ public class GifCaptcha extends AbstractCaptcha {
}
/**
* 设置验证码字符颜色
* 设置验证码字符最小取色范围
*
* @param minColor 颜色
* @return this

View File

@ -126,11 +126,12 @@ public class GraphicsUtil {
* @param str 字符串
* @param font 字体
* @param color 字体颜色{@code null} 表示使用随机颜色每个字符单独随机
* @param width 字符串总宽度
* @param height 字符串背景的高度
* @return 画笔对象
* @since 6.0.0
*/
public static Graphics drawString(final Graphics g, final String str, final Font font, final Color color, final int height) {
public static Graphics drawString(final Graphics g, final String str, final Font font, final Color color, final int width, final int height) {
// 抗锯齿
enableAntialias(g);
// 创建字体
@ -138,10 +139,14 @@ public class GraphicsUtil {
// 文字高度必须在设置字体后调用
final int midY = getCenterY(g, height);
final int len = str.length();
final int charWidth = width / len;
if (null != color) {
g.setColor(color);
}
g.drawString(str, 0, midY);
for (int i = 0; i < len; i++) {
g.drawString(String.valueOf(str.charAt(i)), i * charWidth, midY);
}
return g;
}