mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
b5cba1db65
commit
67463d5dc4
@ -132,7 +132,7 @@ public class GifCaptcha extends AbstractCaptcha {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置验证码字符颜色
|
* 设置验证码字符最大取色范围
|
||||||
*
|
*
|
||||||
* @param maxColor 颜色
|
* @param maxColor 颜色
|
||||||
* @return this
|
* @return this
|
||||||
@ -143,7 +143,7 @@ public class GifCaptcha extends AbstractCaptcha {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置验证码字符颜色
|
* 设置验证码字符最小取色范围
|
||||||
*
|
*
|
||||||
* @param minColor 颜色
|
* @param minColor 颜色
|
||||||
* @return this
|
* @return this
|
||||||
|
@ -126,11 +126,12 @@ public class GraphicsUtil {
|
|||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
* @param font 字体
|
* @param font 字体
|
||||||
* @param color 字体颜色,{@code null} 表示使用随机颜色(每个字符单独随机)
|
* @param color 字体颜色,{@code null} 表示使用随机颜色(每个字符单独随机)
|
||||||
|
* @param width 字符串总宽度
|
||||||
* @param height 字符串背景的高度
|
* @param height 字符串背景的高度
|
||||||
* @return 画笔对象
|
* @return 画笔对象
|
||||||
* @since 6.0.0
|
* @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);
|
enableAntialias(g);
|
||||||
// 创建字体
|
// 创建字体
|
||||||
@ -138,10 +139,14 @@ public class GraphicsUtil {
|
|||||||
|
|
||||||
// 文字高度(必须在设置字体后调用)
|
// 文字高度(必须在设置字体后调用)
|
||||||
final int midY = getCenterY(g, height);
|
final int midY = getCenterY(g, height);
|
||||||
|
final int len = str.length();
|
||||||
|
final int charWidth = width / len;
|
||||||
if (null != color) {
|
if (null != color) {
|
||||||
g.setColor(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;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user