mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
Captcha.setBackground为null时背景透明
This commit is contained in:
parent
4085d8d051
commit
1b4fb6d8e4
@ -72,7 +72,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
|
||||
/**
|
||||
* 背景色
|
||||
*/
|
||||
protected Color background;
|
||||
protected Color background = Color.WHITE;
|
||||
/**
|
||||
* 文字透明度
|
||||
*/
|
||||
@ -267,7 +267,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景色
|
||||
* 设置背景色,{@code null}表示透明背景
|
||||
*
|
||||
* @param background 背景色
|
||||
* @since 4.1.22
|
||||
|
@ -12,14 +12,12 @@
|
||||
|
||||
package org.dromara.hutool.swing.captcha;
|
||||
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
import org.dromara.hutool.core.util.RandomUtil;
|
||||
import org.dromara.hutool.swing.captcha.generator.CodeGenerator;
|
||||
import org.dromara.hutool.swing.captcha.generator.RandomGenerator;
|
||||
import org.dromara.hutool.swing.img.color.ColorUtil;
|
||||
import org.dromara.hutool.swing.img.GraphicsUtil;
|
||||
import org.dromara.hutool.swing.img.color.ColorUtil;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
@ -94,8 +92,8 @@ public class CircleCaptcha extends AbstractCaptcha {
|
||||
|
||||
@Override
|
||||
public Image createImage(final String code) {
|
||||
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
final Graphics2D g = GraphicsUtil.createGraphics(image, ObjUtil.defaultIfNull(this.background, Color.WHITE));
|
||||
final BufferedImage image = new BufferedImage(width, height, (null == this.background) ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_INT_RGB);
|
||||
final Graphics2D g = GraphicsUtil.createGraphics(image, this.background);
|
||||
|
||||
try {
|
||||
// 随机画干扰圈圈
|
||||
|
@ -12,14 +12,12 @@
|
||||
|
||||
package org.dromara.hutool.swing.captcha;
|
||||
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
import org.dromara.hutool.core.util.RandomUtil;
|
||||
import org.dromara.hutool.swing.captcha.generator.CodeGenerator;
|
||||
import org.dromara.hutool.swing.captcha.generator.RandomGenerator;
|
||||
import org.dromara.hutool.swing.img.color.ColorUtil;
|
||||
import org.dromara.hutool.swing.img.GraphicsUtil;
|
||||
import org.dromara.hutool.swing.img.color.ColorUtil;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
@ -88,8 +86,8 @@ public class LineCaptcha extends AbstractCaptcha {
|
||||
@Override
|
||||
public Image createImage(final String code) {
|
||||
// 图像buffer
|
||||
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
final Graphics2D g = GraphicsUtil.createGraphics(image, ObjUtil.defaultIfNull(this.background, Color.WHITE));
|
||||
final BufferedImage image = new BufferedImage(width, height, (null == this.background) ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_INT_RGB);
|
||||
final Graphics2D g = GraphicsUtil.createGraphics(image, this.background);
|
||||
|
||||
try {
|
||||
// 干扰线
|
||||
|
@ -94,8 +94,8 @@ public class ShearCaptcha extends AbstractCaptcha {
|
||||
|
||||
@Override
|
||||
public Image createImage(final String code) {
|
||||
final BufferedImage image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB);
|
||||
final Graphics2D g = GraphicsUtil.createGraphics(image, ObjUtil.defaultIfNull(this.background, Color.WHITE));
|
||||
final BufferedImage image = new BufferedImage(width, height, (null == this.background) ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_INT_RGB);
|
||||
final Graphics2D g = GraphicsUtil.createGraphics(image, this.background);
|
||||
|
||||
try {
|
||||
// 画字符串
|
||||
|
Loading…
x
Reference in New Issue
Block a user