This commit is contained in:
Looly
2022-04-30 20:47:32 +08:00
parent dea8344d91
commit ca094ca4a8
1356 changed files with 15747 additions and 16033 deletions

View File

@@ -31,7 +31,7 @@ public class DesktopUtil {
*
* @param url URL地址
*/
public static void browse(String url) {
public static void browse(final String url) {
browse(URLUtil.toURI(url));
}
@@ -41,11 +41,11 @@ public class DesktopUtil {
* @param uri URI地址
* @since 4.6.3
*/
public static void browse(URI uri) {
public static void browse(final URI uri) {
final Desktop dsktop = getDsktop();
try {
dsktop.browse(uri);
} catch (IOException e) {
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
@@ -55,11 +55,11 @@ public class DesktopUtil {
*
* @param file URL地址
*/
public static void open(File file) {
public static void open(final File file) {
final Desktop dsktop = getDsktop();
try {
dsktop.open(file);
} catch (IOException e) {
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
@@ -69,11 +69,11 @@ public class DesktopUtil {
*
* @param file 文件
*/
public static void edit(File file) {
public static void edit(final File file) {
final Desktop dsktop = getDsktop();
try {
dsktop.edit(file);
} catch (IOException e) {
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
@@ -83,11 +83,11 @@ public class DesktopUtil {
*
* @param file 文件
*/
public static void print(File file) {
public static void print(final File file) {
final Desktop dsktop = getDsktop();
try {
dsktop.print(file);
} catch (IOException e) {
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
@@ -97,11 +97,11 @@ public class DesktopUtil {
*
* @param mailAddress 邮件地址
*/
public static void mail(String mailAddress) {
public static void mail(final String mailAddress) {
final Desktop dsktop = getDsktop();
try {
dsktop.mail(URLUtil.toURI(mailAddress));
} catch (IOException e) {
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}

View File

@@ -26,7 +26,7 @@ public class RobotUtil {
static {
try {
ROBOT = new Robot();
} catch (AWTException e) {
} catch (final AWTException e) {
throw new UtilException(e);
}
}
@@ -48,7 +48,7 @@ public class RobotUtil {
* @param delayMillis 等待毫秒数
* @since 4.5.7
*/
public static void setDelay(int delayMillis) {
public static void setDelay(final int delayMillis) {
delay = delayMillis;
}
@@ -69,7 +69,7 @@ public class RobotUtil {
* @param y 移动到的y坐标
* @since 4.5.7
*/
public static void mouseMove(int x, int y) {
public static void mouseMove(final int x, final int y) {
ROBOT.mouseMove(x, y);
}
@@ -103,7 +103,7 @@ public class RobotUtil {
* @param wheelAmt 滚动数,负数表示向前滚动,正数向后滚动
* @since 4.5.7
*/
public static void mouseWheel(int wheelAmt) {
public static void mouseWheel(final int wheelAmt) {
ROBOT.mouseWheel(wheelAmt);
delay();
}
@@ -115,8 +115,8 @@ public class RobotUtil {
* @param keyCodes 按键码列表,见{@link java.awt.event.KeyEvent}
* @since 4.5.7
*/
public static void keyClick(int... keyCodes) {
for (int keyCode : keyCodes) {
public static void keyClick(final int... keyCodes) {
for (final int keyCode : keyCodes) {
ROBOT.keyPress(keyCode);
ROBOT.keyRelease(keyCode);
}
@@ -128,7 +128,7 @@ public class RobotUtil {
*
* @param str 字符串
*/
public static void keyPressString(String str) {
public static void keyPressString(final String str) {
ClipboardUtil.setStr(str);
keyPressWithCtrl(KeyEvent.VK_V);// 粘贴
delay();
@@ -139,7 +139,7 @@ public class RobotUtil {
*
* @param key 按键
*/
public static void keyPressWithShift(int key) {
public static void keyPressWithShift(final int key) {
ROBOT.keyPress(KeyEvent.VK_SHIFT);
ROBOT.keyPress(key);
ROBOT.keyRelease(key);
@@ -152,7 +152,7 @@ public class RobotUtil {
*
* @param key 按键
*/
public static void keyPressWithCtrl(int key) {
public static void keyPressWithCtrl(final int key) {
ROBOT.keyPress(KeyEvent.VK_CONTROL);
ROBOT.keyPress(key);
ROBOT.keyRelease(key);
@@ -165,7 +165,7 @@ public class RobotUtil {
*
* @param key 按键
*/
public static void keyPressWithAlt(int key) {
public static void keyPressWithAlt(final int key) {
ROBOT.keyPress(KeyEvent.VK_ALT);
ROBOT.keyPress(key);
ROBOT.keyRelease(key);
@@ -188,7 +188,7 @@ public class RobotUtil {
* @param outFile 写出到的文件
* @return 写出到的文件
*/
public static File captureScreen(File outFile) {
public static File captureScreen(final File outFile) {
ImgUtil.write(captureScreen(), outFile);
return outFile;
}
@@ -199,7 +199,7 @@ public class RobotUtil {
* @param screenRect 截屏的矩形区域
* @return 截屏的图片
*/
public static BufferedImage captureScreen(Rectangle screenRect) {
public static BufferedImage captureScreen(final Rectangle screenRect) {
return ROBOT.createScreenCapture(screenRect);
}
@@ -210,7 +210,7 @@ public class RobotUtil {
* @param outFile 写出到的文件
* @return 写出到的文件
*/
public static File captureScreen(Rectangle screenRect, File outFile) {
public static File captureScreen(final Rectangle screenRect, final File outFile) {
ImgUtil.write(captureScreen(screenRect), outFile);
return outFile;
}

View File

@@ -59,7 +59,7 @@ public class ScreenUtil {
* @return 写出到的文件
* @see RobotUtil#captureScreen(File)
*/
public static File captureScreen(File outFile) {
public static File captureScreen(final File outFile) {
return RobotUtil.captureScreen(outFile);
}
@@ -70,7 +70,7 @@ public class ScreenUtil {
* @return 截屏的图片
* @see RobotUtil#captureScreen(Rectangle)
*/
public static BufferedImage captureScreen(Rectangle screenRect) {
public static BufferedImage captureScreen(final Rectangle screenRect) {
return RobotUtil.captureScreen(screenRect);
}
@@ -82,7 +82,7 @@ public class ScreenUtil {
* @return 写出到的文件
* @see RobotUtil#captureScreen(Rectangle, File)
*/
public static File captureScreen(Rectangle screenRect, File outFile) {
public static File captureScreen(final Rectangle screenRect, final File outFile) {
return RobotUtil.captureScreen(screenRect, outFile);
}
}

View File

@@ -74,7 +74,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
* @param codeCount 字符个数
* @param interfereCount 验证码干扰元素个数
*/
public AbstractCaptcha(int width, int height, int codeCount, int interfereCount) {
public AbstractCaptcha(final int width, final int height, final int codeCount, final int interfereCount) {
this(width, height, new RandomGenerator(codeCount), interfereCount);
}
@@ -86,7 +86,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
* @param generator 验证码生成器
* @param interfereCount 验证码干扰元素个数
*/
public AbstractCaptcha(int width, int height, CodeGenerator generator, int interfereCount) {
public AbstractCaptcha(final int width, final int height, final CodeGenerator generator, final int interfereCount) {
this.width = width;
this.height = height;
this.generator = generator;
@@ -130,7 +130,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
}
@Override
public boolean verify(String userInputCode) {
public boolean verify(final String userInputCode) {
return this.generator.verify(getCode(), userInputCode);
}
@@ -140,7 +140,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
* @param path 文件路径
* @throws IORuntimeException IO异常
*/
public void write(String path) throws IORuntimeException {
public void write(final String path) throws IORuntimeException {
this.write(FileUtil.touch(path));
}
@@ -150,16 +150,16 @@ public abstract class AbstractCaptcha implements ICaptcha {
* @param file 文件
* @throws IORuntimeException IO异常
*/
public void write(File file) throws IORuntimeException {
try (OutputStream out = FileUtil.getOutputStream(file)) {
public void write(final File file) throws IORuntimeException {
try (final OutputStream out = FileUtil.getOutputStream(file)) {
this.write(out);
} catch (IOException e) {
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
@Override
public void write(OutputStream out) {
public void write(final OutputStream out) {
IoUtil.write(out, false, getImageBytes());
}
@@ -210,7 +210,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
*
* @param font 字体
*/
public void setFont(Font font) {
public void setFont(final Font font) {
this.font = font;
}
@@ -228,7 +228,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
*
* @param generator 验证码生成器
*/
public void setGenerator(CodeGenerator generator) {
public void setGenerator(final CodeGenerator generator) {
this.generator = generator;
}
@@ -238,7 +238,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
* @param background 背景色
* @since 4.1.22
*/
public void setBackground(Color background) {
public void setBackground(final Color background) {
this.background = background;
}
@@ -248,7 +248,7 @@ public abstract class AbstractCaptcha implements ICaptcha {
* @param textAlpha 文字透明度取值0~11表示不透明
* @since 4.5.17
*/
public void setTextAlpha(float textAlpha) {
public void setTextAlpha(final float textAlpha) {
this.textAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, textAlpha);
}

View File

@@ -15,7 +15,7 @@ public class CaptchaUtil {
* @param height 图片高
* @return {@link LineCaptcha}
*/
public static LineCaptcha createLineCaptcha(int width, int height) {
public static LineCaptcha createLineCaptcha(final int width, final int height) {
return new LineCaptcha(width, height);
}
@@ -28,7 +28,7 @@ public class CaptchaUtil {
* @param lineCount 干扰线条数
* @return {@link LineCaptcha}
*/
public static LineCaptcha createLineCaptcha(int width, int height, int codeCount, int lineCount) {
public static LineCaptcha createLineCaptcha(final int width, final int height, final int codeCount, final int lineCount) {
return new LineCaptcha(width, height, codeCount, lineCount);
}
@@ -40,7 +40,7 @@ public class CaptchaUtil {
* @return {@link CircleCaptcha}
* @since 3.2.3
*/
public static CircleCaptcha createCircleCaptcha(int width, int height) {
public static CircleCaptcha createCircleCaptcha(final int width, final int height) {
return new CircleCaptcha(width, height);
}
@@ -54,7 +54,7 @@ public class CaptchaUtil {
* @return {@link CircleCaptcha}
* @since 3.2.3
*/
public static CircleCaptcha createCircleCaptcha(int width, int height, int codeCount, int circleCount) {
public static CircleCaptcha createCircleCaptcha(final int width, final int height, final int codeCount, final int circleCount) {
return new CircleCaptcha(width, height, codeCount, circleCount);
}
@@ -66,7 +66,7 @@ public class CaptchaUtil {
* @return {@link ShearCaptcha}
* @since 3.2.3
*/
public static ShearCaptcha createShearCaptcha(int width, int height) {
public static ShearCaptcha createShearCaptcha(final int width, final int height) {
return new ShearCaptcha(width, height);
}
@@ -80,7 +80,7 @@ public class CaptchaUtil {
* @return {@link ShearCaptcha}
* @since 3.3.0
*/
public static ShearCaptcha createShearCaptcha(int width, int height, int codeCount, int thickness) {
public static ShearCaptcha createShearCaptcha(final int width, final int height, final int codeCount, final int thickness) {
return new ShearCaptcha(width, height, codeCount, thickness);
}
@@ -91,7 +91,7 @@ public class CaptchaUtil {
* @param height 高
* @return {@link GifCaptcha}
*/
public static GifCaptcha createGifCaptcha(int width, int height) {
public static GifCaptcha createGifCaptcha(final int width, final int height) {
return new GifCaptcha(width, height);
}
@@ -103,7 +103,7 @@ public class CaptchaUtil {
* @param codeCount 字符个数
* @return {@link GifCaptcha}
*/
public static GifCaptcha createGifCaptcha(int width, int height, int codeCount) {
public static GifCaptcha createGifCaptcha(final int width, final int height, final int codeCount) {
return new GifCaptcha(width, height, codeCount);
}
}

View File

@@ -27,7 +27,7 @@ public class CircleCaptcha extends AbstractCaptcha {
* @param width 图片宽
* @param height 图片高
*/
public CircleCaptcha(int width, int height) {
public CircleCaptcha(final int width, final int height) {
this(width, height, 5);
}
@@ -38,7 +38,7 @@ public class CircleCaptcha extends AbstractCaptcha {
* @param height 图片高
* @param codeCount 字符个数
*/
public CircleCaptcha(int width, int height, int codeCount) {
public CircleCaptcha(final int width, final int height, final int codeCount) {
this(width, height, codeCount, 15);
}
@@ -50,12 +50,12 @@ public class CircleCaptcha extends AbstractCaptcha {
* @param codeCount 字符个数
* @param interfereCount 验证码干扰元素个数
*/
public CircleCaptcha(int width, int height, int codeCount, int interfereCount) {
public CircleCaptcha(final int width, final int height, final int codeCount, final int interfereCount) {
super(width, height, codeCount, interfereCount);
}
@Override
public Image createImage(String code) {
public Image createImage(final String code) {
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = ImgUtil.createGraphics(image, ObjUtil.defaultIfNull(this.background, Color.WHITE));
@@ -75,7 +75,7 @@ public class CircleCaptcha extends AbstractCaptcha {
* @param g {@link Graphics2D}画笔
* @param code 验证码
*/
private void drawString(Graphics2D g, String code) {
private void drawString(final Graphics2D g, final String code) {
// 指定透明度
if (null != this.textAlpha) {
g.setComposite(this.textAlpha);
@@ -88,7 +88,7 @@ public class CircleCaptcha extends AbstractCaptcha {
*
* @param g {@link Graphics2D}
*/
private void drawInterfere(Graphics2D g) {
private void drawInterfere(final Graphics2D g) {
final ThreadLocalRandom random = RandomUtil.getRandom();
for (int i = 0; i < this.interfereCount; i++) {

View File

@@ -37,7 +37,7 @@ public class GifCaptcha extends AbstractCaptcha {
* @param width 验证码宽度
* @param height 验证码高度
*/
public GifCaptcha(int width, int height) {
public GifCaptcha(final int width, final int height) {
this(width, height, 5);
}
@@ -46,7 +46,7 @@ public class GifCaptcha extends AbstractCaptcha {
* @param height 验证码高度
* @param codeCount 验证码个数
*/
public GifCaptcha(int width, int height, int codeCount) {
public GifCaptcha(final int width, final int height, final int codeCount) {
super(width, height, codeCount, 10);
}
@@ -75,7 +75,7 @@ public class GifCaptcha extends AbstractCaptcha {
* @param repeat 必须大于等于0
* @return this
*/
public GifCaptcha setRepeat(int repeat) {
public GifCaptcha setRepeat(final int repeat) {
if (repeat >= 0) {
this.repeat = repeat;
}
@@ -88,7 +88,7 @@ public class GifCaptcha extends AbstractCaptcha {
* @param maxColor 颜色
* @return this
*/
public GifCaptcha setMaxColor(int maxColor) {
public GifCaptcha setMaxColor(final int maxColor) {
this.maxColor = maxColor;
return this;
}
@@ -99,7 +99,7 @@ public class GifCaptcha extends AbstractCaptcha {
* @param minColor 颜色
* @return this
*/
public GifCaptcha setMinColor(int minColor) {
public GifCaptcha setMinColor(final int minColor) {
this.minColor = minColor;
return this;
}
@@ -109,17 +109,17 @@ public class GifCaptcha extends AbstractCaptcha {
generateCode();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
AnimatedGifEncoder gifEncoder = new AnimatedGifEncoder();// gif编码类
final AnimatedGifEncoder gifEncoder = new AnimatedGifEncoder();// gif编码类
//生成字符
gifEncoder.start(out);
gifEncoder.setQuality(quality);//设置量化器取样间隔
// 帧延迟 (默认100)
int delay = 100;
final int delay = 100;
gifEncoder.setDelay(delay);//设置帧延迟
gifEncoder.setRepeat(repeat);//帧循环次数
BufferedImage frame;
char[] chars = code.toCharArray();
Color[] fontColor = new Color[chars.length];
final char[] chars = code.toCharArray();
final Color[] fontColor = new Color[chars.length];
for (int i = 0; i < chars.length; i++) {
fontColor[i] = getRandomColor(minColor, maxColor);
frame = graphicsImage(chars, fontColor, chars, i);
@@ -131,7 +131,7 @@ public class GifCaptcha extends AbstractCaptcha {
}
@Override
protected Image createImage(String code) {
protected Image createImage(final String code) {
return null;
}
@@ -143,19 +143,19 @@ public class GifCaptcha extends AbstractCaptcha {
* @param flag 透明度使用
* @return BufferedImage
*/
private BufferedImage graphicsImage(char[] chars, Color[] fontColor, char[] words, int flag) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
private BufferedImage graphicsImage(final char[] chars, final Color[] fontColor, final char[] words, final int flag) {
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//或得图形上下文
Graphics2D g2d = image.createGraphics();
final Graphics2D g2d = image.createGraphics();
//利用指定颜色填充背景
g2d.setColor(ObjUtil.defaultIfNull(this.background, Color.WHITE));
g2d.fillRect(0, 0, width, height);
AlphaComposite ac;
// 字符的y坐标
float y = (height >> 1) + (font.getSize() >> 1);
float m = 1.0f * (width - (chars.length * font.getSize())) / chars.length;
final float y = (height >> 1) + (font.getSize() >> 1);
final float m = 1.0f * (width - (chars.length * font.getSize())) / chars.length;
//字符的x坐标
float x = Math.max(m / 2.0f, 2);
final float x = Math.max(m / 2.0f, 2);
g2d.setFont(font);
// 指定透明度
if (null != this.textAlpha) {
@@ -181,10 +181,10 @@ public class GifCaptcha extends AbstractCaptcha {
*
* @return float 透明度
*/
private float getAlpha(int v, int i, int j) {
int num = i + j;
float r = (float) 1 / v;
float s = (v + 1) * r;
private float getAlpha(final int v, final int i, final int j) {
final int num = i + j;
final float r = (float) 1 / v;
final float s = (v + 1) * r;
return num > v ? (num * r - s) : num * r;
}

View File

@@ -28,7 +28,7 @@ public class LineCaptcha extends AbstractCaptcha {
* @param width 图片宽
* @param height 图片高
*/
public LineCaptcha(int width, int height) {
public LineCaptcha(final int width, final int height) {
this(width, height, 5, 150);
}
@@ -40,13 +40,13 @@ public class LineCaptcha extends AbstractCaptcha {
* @param codeCount 字符个数
* @param lineCount 干扰线条数
*/
public LineCaptcha(int width, int height, int codeCount, int lineCount) {
public LineCaptcha(final int width, final int height, final int codeCount, final int lineCount) {
super(width, height, codeCount, lineCount);
}
// -------------------------------------------------------------------- Constructor end
@Override
public Image createImage(String code) {
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));
@@ -67,7 +67,7 @@ public class LineCaptcha extends AbstractCaptcha {
* @param g {@link Graphics}画笔
* @param code 验证码
*/
private void drawString(Graphics2D g, String code) {
private void drawString(final Graphics2D g, final String code) {
// 指定透明度
if (null != this.textAlpha) {
g.setComposite(this.textAlpha);
@@ -80,14 +80,14 @@ public class LineCaptcha extends AbstractCaptcha {
*
* @param g {@link Graphics2D}画笔
*/
private void drawInterfere(Graphics2D g) {
private void drawInterfere(final Graphics2D g) {
final ThreadLocalRandom random = RandomUtil.getRandom();
// 干扰线
for (int i = 0; i < this.interfereCount; i++) {
int xs = random.nextInt(width);
int ys = random.nextInt(height);
int xe = xs + random.nextInt(width / 8);
int ye = ys + random.nextInt(height / 8);
final int xs = random.nextInt(width);
final int ys = random.nextInt(height);
final int xe = xs + random.nextInt(width / 8);
final int ye = ys + random.nextInt(height / 8);
g.setColor(ImgUtil.randomColor(random));
g.drawLine(xs, ys, xe, ye);
}

View File

@@ -27,7 +27,7 @@ public class ShearCaptcha extends AbstractCaptcha {
* @param width 图片宽
* @param height 图片高
*/
public ShearCaptcha(int width, int height) {
public ShearCaptcha(final int width, final int height) {
this(width, height, 5);
}
@@ -38,7 +38,7 @@ public class ShearCaptcha extends AbstractCaptcha {
* @param height 图片高
* @param codeCount 字符个数
*/
public ShearCaptcha(int width, int height, int codeCount) {
public ShearCaptcha(final int width, final int height, final int codeCount) {
this(width, height, codeCount, 4);
}
@@ -50,12 +50,12 @@ public class ShearCaptcha extends AbstractCaptcha {
* @param codeCount 字符个数
* @param thickness 干扰线宽度
*/
public ShearCaptcha(int width, int height, int codeCount, int thickness) {
public ShearCaptcha(final int width, final int height, final int codeCount, final int thickness) {
super(width, height, codeCount, thickness);
}
@Override
public Image createImage(String code) {
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));
@@ -77,7 +77,7 @@ public class ShearCaptcha extends AbstractCaptcha {
* @param g {@link Graphics}画笔
* @param code 验证码
*/
private void drawString(Graphics2D g, String code) {
private void drawString(final Graphics2D g, final String code) {
// 指定透明度
if (null != this.textAlpha) {
g.setComposite(this.textAlpha);
@@ -93,7 +93,7 @@ public class ShearCaptcha extends AbstractCaptcha {
* @param h1 h1
* @param color 颜色
*/
private void shear(Graphics g, int w1, int h1, Color color) {
private void shear(final Graphics g, final int w1, final int h1, final Color color) {
shearX(g, w1, h1, color);
shearY(g, w1, h1, color);
}
@@ -106,15 +106,15 @@ public class ShearCaptcha extends AbstractCaptcha {
* @param h1 高
* @param color 颜色
*/
private void shearX(Graphics g, int w1, int h1, Color color) {
private void shearX(final Graphics g, final int w1, final int h1, final Color color) {
int period = RandomUtil.randomInt(this.width);
final int period = RandomUtil.randomInt(this.width);
int frames = 1;
int phase = RandomUtil.randomInt(2);
final int frames = 1;
final int phase = RandomUtil.randomInt(2);
for (int i = 0; i < h1; i++) {
double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
final double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
g.copyArea(0, i, w1, 1, (int) d, 0);
g.setColor(color);
g.drawLine((int) d, i, 0, i);
@@ -131,14 +131,14 @@ public class ShearCaptcha extends AbstractCaptcha {
* @param h1 高
* @param color 颜色
*/
private void shearY(Graphics g, int w1, int h1, Color color) {
private void shearY(final Graphics g, final int w1, final int h1, final Color color) {
int period = RandomUtil.randomInt(this.height >> 1);
final int period = RandomUtil.randomInt(this.height >> 1);
int frames = 20;
int phase = 7;
final int frames = 20;
final int phase = 7;
for (int i = 0; i < w1; i++) {
double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
final double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
g.copyArea(i, 0, 1, h1, 0, (int) d);
g.setColor(color);
// 擦除原位置的痕迹
@@ -160,16 +160,16 @@ public class ShearCaptcha extends AbstractCaptcha {
* @param c 颜色
*/
@SuppressWarnings("SameParameterValue")
private void drawInterfere(Graphics g, int x1, int y1, int x2, int y2, int thickness, Color c) {
private void drawInterfere(final Graphics g, final int x1, final int y1, final int x2, final int y2, final int thickness, final Color c) {
// The thick line is in fact a filled polygon
g.setColor(c);
int dX = x2 - x1;
int dY = y2 - y1;
final int dX = x2 - x1;
final int dY = y2 - y1;
// line length
double lineLength = Math.sqrt(dX * dX + dY * dY);
final double lineLength = Math.sqrt(dX * dX + dY * dY);
double scale = (double) (thickness) / (2 * lineLength);
final double scale = (double) (thickness) / (2 * lineLength);
// The x and y increments from an endpoint needed to create a
// rectangle...
@@ -177,12 +177,12 @@ public class ShearCaptcha extends AbstractCaptcha {
double ddy = scale * (double) dX;
ddx += (ddx > 0) ? 0.5 : -0.5;
ddy += (ddy > 0) ? 0.5 : -0.5;
int dx = (int) ddx;
int dy = (int) ddy;
final int dx = (int) ddx;
final int dy = (int) ddy;
// Now we can compute the corner points...
int[] xPoints = new int[4];
int[] yPoints = new int[4];
final int[] xPoints = new int[4];
final int[] yPoints = new int[4];
xPoints[0] = x1 + dx;
yPoints[0] = y1 + dy;

View File

@@ -22,7 +22,7 @@ public abstract class AbstractGenerator implements CodeGenerator {
*
* @param count 生成验证码长度
*/
public AbstractGenerator(int count) {
public AbstractGenerator(final int count) {
this(RandomUtil.BASE_CHAR_NUMBER, count);
}
@@ -32,7 +32,7 @@ public abstract class AbstractGenerator implements CodeGenerator {
* @param baseStr 基础字符集合,用于随机获取字符串的字符集合
* @param length 生成验证码长度
*/
public AbstractGenerator(String baseStr, int length) {
public AbstractGenerator(final String baseStr, final int length) {
this.baseStr = baseStr;
this.length = length;
}

View File

@@ -31,7 +31,7 @@ public class MathGenerator implements CodeGenerator {
*
* @param numberLength 参与计算最大数字位数
*/
public MathGenerator(int numberLength) {
public MathGenerator(final int numberLength) {
this.numberLength = numberLength;
}
@@ -51,11 +51,11 @@ public class MathGenerator implements CodeGenerator {
}
@Override
public boolean verify(String code, String userInputCode) {
int result;
public boolean verify(final String code, final String userInputCode) {
final int result;
try {
result = Integer.parseInt(userInputCode);
} catch (NumberFormatException e) {
} catch (final NumberFormatException e) {
// 用户输入非数字
return false;
}

View File

@@ -18,7 +18,7 @@ public class RandomGenerator extends AbstractGenerator {
*
* @param count 生成验证码长度
*/
public RandomGenerator(int count) {
public RandomGenerator(final int count) {
super(count);
}
@@ -28,7 +28,7 @@ public class RandomGenerator extends AbstractGenerator {
* @param baseStr 基础字符集合,用于随机获取字符串的字符集合
* @param length 生成验证码长度
*/
public RandomGenerator(String baseStr, int length) {
public RandomGenerator(final String baseStr, final int length) {
super(baseStr, length);
}
@@ -38,7 +38,7 @@ public class RandomGenerator extends AbstractGenerator {
}
@Override
public boolean verify(String code, String userInputCode) {
public boolean verify(final String code, final String userInputCode) {
if (StrUtil.isNotBlank(userInputCode)) {
return StrUtil.equalsIgnoreCase(code, userInputCode);
}

View File

@@ -49,7 +49,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param tryCount 尝试获取剪贴板内容的次数
* @param delay 响应延迟当从第二次开始延迟一定毫秒数等待剪贴板可以获取当tryCount小于2时无效
*/
ClipboardMonitor(int tryCount, long delay) {
ClipboardMonitor(final int tryCount, final long delay) {
this(tryCount, delay, ClipboardUtil.getClipboard());
}
@@ -60,7 +60,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param delay 响应延迟当从第二次开始延迟一定毫秒数等待剪贴板可以获取当tryCount小于2时无效
* @param clipboard 剪贴板对象
*/
ClipboardMonitor(int tryCount, long delay, Clipboard clipboard) {
ClipboardMonitor(final int tryCount, final long delay, final Clipboard clipboard) {
this.tryCount = tryCount;
this.delay = delay;
this.clipboard = clipboard;
@@ -73,7 +73,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param tryCount 重试次数
* @return this
*/
public ClipboardMonitor setTryCount(int tryCount) {
public ClipboardMonitor setTryCount(final int tryCount) {
this.tryCount = tryCount;
return this;
}
@@ -84,7 +84,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param delay 重试等待
* @return this
*/
public ClipboardMonitor setDelay(long delay) {
public ClipboardMonitor setDelay(final long delay) {
this.delay = delay;
return this;
}
@@ -95,7 +95,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param listener 监听事件处理
* @return this
*/
public ClipboardMonitor addListener(ClipboardListener listener) {
public ClipboardMonitor addListener(final ClipboardListener listener) {
this.listenerSet.add(listener);
return this;
}
@@ -106,7 +106,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param listener 监听
* @return this
*/
public ClipboardMonitor removeListener(ClipboardListener listener) {
public ClipboardMonitor removeListener(final ClipboardListener listener) {
this.listenerSet.remove(listener);
return this;
}
@@ -122,20 +122,20 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
}
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
Transferable newContents;
public void lostOwnership(final Clipboard clipboard, final Transferable contents) {
final Transferable newContents;
try {
newContents = tryGetContent(clipboard);
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
// 中断后结束简体
return;
}
Transferable transferable = null;
for (ClipboardListener listener : listenerSet) {
for (final ClipboardListener listener : listenerSet) {
try {
transferable = listener.onChange(clipboard, ObjUtil.defaultIfNull(transferable, newContents));
} catch (Throwable e) {
} catch (final Throwable e) {
// 忽略事件处理异常,保证所有监听正常执行
}
}
@@ -160,7 +160,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
*
* @param sync 是否阻塞
*/
public void listen(boolean sync) {
public void listen(final boolean sync) {
run();
if (sync) {
@@ -184,7 +184,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @return 剪贴板内容,{@code null} 表示未获取到
* @throws InterruptedException 线程中断
*/
private Transferable tryGetContent(Clipboard clipboard) throws InterruptedException {
private Transferable tryGetContent(final Clipboard clipboard) throws InterruptedException {
Transferable newContents = null;
for (int i = 0; i < this.tryCount; i++) {
if (this.delay > 0 && i > 0) {
@@ -195,7 +195,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
try {
newContents = clipboard.getContents(null);
} catch (IllegalStateException e) {
} catch (final IllegalStateException e) {
// ignore
}
if (null != newContents) {

View File

@@ -34,7 +34,7 @@ public class ClipboardUtil {
*
* @param contents 内容
*/
public static void set(Transferable contents) {
public static void set(final Transferable contents) {
set(contents, null);
}
@@ -44,7 +44,7 @@ public class ClipboardUtil {
* @param contents 内容
* @param owner 所有者
*/
public static void set(Transferable contents, ClipboardOwner owner) {
public static void set(final Transferable contents, final ClipboardOwner owner) {
getClipboard().setContents(contents, owner);
}
@@ -54,7 +54,7 @@ public class ClipboardUtil {
* @param flavor 数据元信息,标识数据类型
* @return 剪贴板内容类型根据flavor不同而不同
*/
public static Object get(DataFlavor flavor) {
public static Object get(final DataFlavor flavor) {
return get(getClipboard().getContents(null), flavor);
}
@@ -65,11 +65,11 @@ public class ClipboardUtil {
* @param flavor 数据元信息,标识数据类型
* @return 剪贴板内容类型根据flavor不同而不同
*/
public static Object get(Transferable content, DataFlavor flavor) {
public static Object get(final Transferable content, final DataFlavor flavor) {
if (null != content && content.isDataFlavorSupported(flavor)) {
try {
return content.getTransferData(flavor);
} catch (UnsupportedFlavorException | IOException e) {
} catch (final UnsupportedFlavorException | IOException e) {
throw new UtilException(e);
}
}
@@ -81,7 +81,7 @@ public class ClipboardUtil {
*
* @param text 字符串文本
*/
public static void setStr(String text) {
public static void setStr(final String text) {
set(new StringSelection(text));
}
@@ -101,7 +101,7 @@ public class ClipboardUtil {
* @return 文本
* @since 4.5.6
*/
public static String getStr(Transferable content) {
public static String getStr(final Transferable content) {
return (String) get(content, DataFlavor.stringFlavor);
}
@@ -110,7 +110,7 @@ public class ClipboardUtil {
*
* @param image 图像
*/
public static void setImage(Image image) {
public static void setImage(final Image image) {
set(new ImageSelection(image), null);
}
@@ -130,7 +130,7 @@ public class ClipboardUtil {
* @return 图片
* @since 4.5.6
*/
public static Image getImage(Transferable content) {
public static Image getImage(final Transferable content) {
return (Image) get(content, DataFlavor.imageFlavor);
}
@@ -141,7 +141,7 @@ public class ClipboardUtil {
* @since 4.5.6
* @see ClipboardMonitor#listen(boolean)
*/
public static void listen(ClipboardListener listener) {
public static void listen(final ClipboardListener listener) {
listen(listener, true);
}
@@ -153,7 +153,7 @@ public class ClipboardUtil {
* @since 4.5.6
* @see ClipboardMonitor#listen(boolean)
*/
public static void listen(ClipboardListener listener, boolean sync) {
public static void listen(final ClipboardListener listener, final boolean sync) {
listen(ClipboardMonitor.DEFAULT_TRY_COUNT, ClipboardMonitor.DEFAULT_DELAY, listener, sync);
}
@@ -167,7 +167,7 @@ public class ClipboardUtil {
* @since 4.5.6
* @see ClipboardMonitor#listen(boolean)
*/
public static void listen(int tryCount, long delay, ClipboardListener listener, boolean sync) {
public static void listen(final int tryCount, final long delay, final ClipboardListener listener, final boolean sync) {
ClipboardMonitor.INSTANCE//
.setTryCount(tryCount)//
.setDelay(delay)//

View File

@@ -23,7 +23,7 @@ public class ImageSelection implements Transferable, Serializable {
*
* @param image 图片
*/
public ImageSelection(Image image) {
public ImageSelection(final Image image) {
this.image = image;
}
@@ -44,7 +44,7 @@ public class ImageSelection implements Transferable, Serializable {
* @return 是否支持
*/
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
public boolean isDataFlavorSupported(final DataFlavor flavor) {
return DataFlavor.imageFlavor.equals(flavor);
}
@@ -55,7 +55,7 @@ public class ImageSelection implements Transferable, Serializable {
* @return 转换后的对象
*/
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException {
if (false == DataFlavor.imageFlavor.equals(flavor)) {
throw new UnsupportedFlavorException(flavor);
}

View File

@@ -15,7 +15,7 @@ public abstract class StrClipboardListener implements ClipboardListener, Seriali
private static final long serialVersionUID = 1L;
@Override
public Transferable onChange(Clipboard clipboard, Transferable contents) {
public Transferable onChange(final Clipboard clipboard, final Transferable contents) {
if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return onChange(clipboard, ClipboardUtil.getStr(contents));
}

View File

@@ -47,7 +47,7 @@ public class BackgroundRemoval {
* @param tolerance 容差值[根据图片的主题色,加入容差值,值的范围在0~255之间]
* @return 返回处理结果 true:图片处理完成 false:图片处理失败
*/
public static boolean backgroundRemoval(String inputPath, String outputPath, int tolerance) {
public static boolean backgroundRemoval(final String inputPath, final String outputPath, final int tolerance) {
return backgroundRemoval(new File(inputPath), new File(outputPath), tolerance);
}
@@ -65,7 +65,7 @@ public class BackgroundRemoval {
* @param tolerance 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]
* @return 返回处理结果 true:图片处理完成 false:图片处理失败
*/
public static boolean backgroundRemoval(File input, File output, int tolerance) {
public static boolean backgroundRemoval(final File input, final File output, final int tolerance) {
return backgroundRemoval(input, output, null, tolerance);
}
@@ -84,16 +84,16 @@ public class BackgroundRemoval {
* @param tolerance 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]
* @return 返回处理结果 true:图片处理完成 false:图片处理失败
*/
public static boolean backgroundRemoval(File input, File output, Color override, int tolerance) {
public static boolean backgroundRemoval(final File input, final File output, final Color override, final int tolerance) {
if (fileTypeValidation(input, IMAGES_TYPE)) {
return false;
}
try {
// 获取图片左上、中上、右上、右中、右下、下中、左下、左中、8个像素点rgb的16进制值
BufferedImage bufferedImage = ImageIO.read(input);
final BufferedImage bufferedImage = ImageIO.read(input);
// 图片输出的格式为 png
return ImageIO.write(backgroundRemoval(bufferedImage, override, tolerance), "png", output);
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
return false;
}
@@ -113,27 +113,27 @@ public class BackgroundRemoval {
* @param tolerance 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]
* @return 返回处理好的图片流
*/
public static BufferedImage backgroundRemoval(BufferedImage bufferedImage, Color override, int tolerance) {
public static BufferedImage backgroundRemoval(final BufferedImage bufferedImage, final Color override, int tolerance) {
// 容差值 最大255 最小0
tolerance = Math.min(255, Math.max(tolerance, 0));
// 绘制icon
ImageIcon imageIcon = new ImageIcon(bufferedImage);
BufferedImage image = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
final ImageIcon imageIcon = new ImageIcon(bufferedImage);
final BufferedImage image = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
BufferedImage.TYPE_4BYTE_ABGR);
// 绘图工具
Graphics graphics = image.getGraphics();
final Graphics graphics = image.getGraphics();
graphics.drawImage(imageIcon.getImage(), 0, 0, imageIcon.getImageObserver());
// 需要删除的RGB元素
String[] removeRgb = getRemoveRgb(bufferedImage);
final String[] removeRgb = getRemoveRgb(bufferedImage);
// 获取图片的大概主色调
String mainColor = getMainColor(bufferedImage);
int alpha = 0;
final String mainColor = getMainColor(bufferedImage);
final int alpha = 0;
for (int y = image.getMinY(); y < image.getHeight(); y++) {
for (int x = image.getMinX(); x < image.getWidth(); x++) {
// 获取像素的16进制
int rgb = image.getRGB(x, y);
String hex = ImgUtil.toHex((rgb & 0xff0000) >> 16, (rgb & 0xff00) >> 8, (rgb & 0xff));
boolean isTrue = ArrayUtil.contains(removeRgb, hex) ||
final String hex = ImgUtil.toHex((rgb & 0xff0000) >> 16, (rgb & 0xff00) >> 8, (rgb & 0xff));
final boolean isTrue = ArrayUtil.contains(removeRgb, hex) ||
areColorsWithinTolerance(hexToRgb(mainColor), new Color(Integer.parseInt(hex.substring(1), 16)), tolerance);
if (isTrue) {
rgb = override == null ? ((alpha + 1) << 24) | (rgb & 0x00ffffff) : override.getRGB();
@@ -159,10 +159,10 @@ public class BackgroundRemoval {
* @param tolerance 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]
* @return 返回处理好的图片流
*/
public static BufferedImage backgroundRemoval(ByteArrayOutputStream outputStream, Color override, int tolerance) {
public static BufferedImage backgroundRemoval(final ByteArrayOutputStream outputStream, final Color override, final int tolerance) {
try {
return backgroundRemoval(ImageIO.read(new ByteArrayInputStream(outputStream.toByteArray())), override, tolerance);
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
return null;
}
@@ -175,34 +175,34 @@ public class BackgroundRemoval {
* @param image 图片流
* @return String数组 包含 各个位置的rgb数值
*/
private static String[] getRemoveRgb(BufferedImage image) {
private static String[] getRemoveRgb(final BufferedImage image) {
// 获取图片流的宽和高
int width = image.getWidth() - 1;
int height = image.getHeight() - 1;
final int width = image.getWidth() - 1;
final int height = image.getHeight() - 1;
// 左上
int leftUpPixel = image.getRGB(1, 1);
String leftUp = ImgUtil.toHex((leftUpPixel & 0xff0000) >> 16, (leftUpPixel & 0xff00) >> 8, (leftUpPixel & 0xff));
final int leftUpPixel = image.getRGB(1, 1);
final String leftUp = ImgUtil.toHex((leftUpPixel & 0xff0000) >> 16, (leftUpPixel & 0xff00) >> 8, (leftUpPixel & 0xff));
// 上中
int upMiddlePixel = image.getRGB(width / 2, 1);
String upMiddle = ImgUtil.toHex((upMiddlePixel & 0xff0000) >> 16, (upMiddlePixel & 0xff00) >> 8, (upMiddlePixel & 0xff));
final int upMiddlePixel = image.getRGB(width / 2, 1);
final String upMiddle = ImgUtil.toHex((upMiddlePixel & 0xff0000) >> 16, (upMiddlePixel & 0xff00) >> 8, (upMiddlePixel & 0xff));
// 右上
int rightUpPixel = image.getRGB(width, 1);
String rightUp = ImgUtil.toHex((rightUpPixel & 0xff0000) >> 16, (rightUpPixel & 0xff00) >> 8, (rightUpPixel & 0xff));
final int rightUpPixel = image.getRGB(width, 1);
final String rightUp = ImgUtil.toHex((rightUpPixel & 0xff0000) >> 16, (rightUpPixel & 0xff00) >> 8, (rightUpPixel & 0xff));
// 右中
int rightMiddlePixel = image.getRGB(width, height / 2);
String rightMiddle = ImgUtil.toHex((rightMiddlePixel & 0xff0000) >> 16, (rightMiddlePixel & 0xff00) >> 8, (rightMiddlePixel & 0xff));
final int rightMiddlePixel = image.getRGB(width, height / 2);
final String rightMiddle = ImgUtil.toHex((rightMiddlePixel & 0xff0000) >> 16, (rightMiddlePixel & 0xff00) >> 8, (rightMiddlePixel & 0xff));
// 右下
int lowerRightPixel = image.getRGB(width, height);
String lowerRight = ImgUtil.toHex((lowerRightPixel & 0xff0000) >> 16, (lowerRightPixel & 0xff00) >> 8, (lowerRightPixel & 0xff));
final int lowerRightPixel = image.getRGB(width, height);
final String lowerRight = ImgUtil.toHex((lowerRightPixel & 0xff0000) >> 16, (lowerRightPixel & 0xff00) >> 8, (lowerRightPixel & 0xff));
// 下中
int lowerMiddlePixel = image.getRGB(width / 2, height);
String lowerMiddle = ImgUtil.toHex((lowerMiddlePixel & 0xff0000) >> 16, (lowerMiddlePixel & 0xff00) >> 8, (lowerMiddlePixel & 0xff));
final int lowerMiddlePixel = image.getRGB(width / 2, height);
final String lowerMiddle = ImgUtil.toHex((lowerMiddlePixel & 0xff0000) >> 16, (lowerMiddlePixel & 0xff00) >> 8, (lowerMiddlePixel & 0xff));
// 左下
int leftLowerPixel = image.getRGB(1, height);
String leftLower = ImgUtil.toHex((leftLowerPixel & 0xff0000) >> 16, (leftLowerPixel & 0xff00) >> 8, (leftLowerPixel & 0xff));
final int leftLowerPixel = image.getRGB(1, height);
final String leftLower = ImgUtil.toHex((leftLowerPixel & 0xff0000) >> 16, (leftLowerPixel & 0xff00) >> 8, (leftLowerPixel & 0xff));
// 左中
int leftMiddlePixel = image.getRGB(1, height / 2);
String leftMiddle = ImgUtil.toHex((leftMiddlePixel & 0xff0000) >> 16, (leftMiddlePixel & 0xff00) >> 8, (leftMiddlePixel & 0xff));
final int leftMiddlePixel = image.getRGB(1, height / 2);
final String leftMiddle = ImgUtil.toHex((leftMiddlePixel & 0xff0000) >> 16, (leftMiddlePixel & 0xff00) >> 8, (leftMiddlePixel & 0xff));
// 需要删除的RGB元素
return new String[]{leftUp, upMiddle, rightUp, rightMiddle, lowerRight, lowerMiddle, leftLower, leftMiddle};
}
@@ -213,7 +213,7 @@ public class BackgroundRemoval {
* @param hex 十六进制颜色码
* @return 返回 RGB颜色值
*/
public static Color hexToRgb(String hex) {
public static Color hexToRgb(final String hex) {
return new Color(Integer.parseInt(hex.substring(1), 16));
}
@@ -227,7 +227,7 @@ public class BackgroundRemoval {
* @param tolerance 容差值
* @return 返回true:两个颜色在容差值之内 false: 不在
*/
public static boolean areColorsWithinTolerance(Color color1, Color color2, int tolerance) {
public static boolean areColorsWithinTolerance(final Color color1, final Color color2, final int tolerance) {
return areColorsWithinTolerance(color1, color2, new Color(tolerance, tolerance, tolerance));
}
@@ -240,7 +240,7 @@ public class BackgroundRemoval {
* @param tolerance 容差色值
* @return 返回true:两个颜色在容差值之内 false: 不在
*/
public static boolean areColorsWithinTolerance(Color color1, Color color2, Color tolerance) {
public static boolean areColorsWithinTolerance(final Color color1, final Color color2, final Color tolerance) {
return (color1.getRed() - color2.getRed() < tolerance.getRed() && color1
.getRed() - color2.getRed() > -tolerance.getRed())
&& (color1.getBlue() - color2.getBlue() < tolerance
@@ -258,7 +258,7 @@ public class BackgroundRemoval {
* @param input 图片文件路径
* @return 返回一个图片的大概的色值 一个16进制的颜色码
*/
public static String getMainColor(String input) {
public static String getMainColor(final String input) {
return getMainColor(new File(input));
}
@@ -269,10 +269,10 @@ public class BackgroundRemoval {
* @param input 图片文件
* @return 返回一个图片的大概的色值 一个16进制的颜色码
*/
public static String getMainColor(File input) {
public static String getMainColor(final File input) {
try {
return getMainColor(ImageIO.read(input));
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
}
return "";
@@ -285,22 +285,22 @@ public class BackgroundRemoval {
* @param bufferedImage 图片流
* @return 返回一个图片的大概的色值 一个16进制的颜色码
*/
public static String getMainColor(BufferedImage bufferedImage) {
public static String getMainColor(final BufferedImage bufferedImage) {
if (bufferedImage == null) {
throw new IllegalArgumentException("图片流是空的");
}
// 存储图片的所有RGB元素
List<String> list = new ArrayList<>();
final List<String> list = new ArrayList<>();
for (int y = bufferedImage.getMinY(); y < bufferedImage.getHeight(); y++) {
for (int x = bufferedImage.getMinX(); x < bufferedImage.getWidth(); x++) {
int pixel = bufferedImage.getRGB(x, y);
final int pixel = bufferedImage.getRGB(x, y);
list.add(((pixel & 0xff0000) >> 16) + "-" + ((pixel & 0xff00) >> 8) + "-" + (pixel & 0xff));
}
}
Map<String, Integer> map = new HashMap<>(list.size());
for (String string : list) {
final Map<String, Integer> map = new HashMap<>(list.size());
for (final String string : list) {
Integer integer = map.get(string);
if (integer == null) {
integer = 1;
@@ -311,17 +311,17 @@ public class BackgroundRemoval {
}
String max = "";
long num = 0;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
String key = entry.getKey();
Integer temp = entry.getValue();
for (final Map.Entry<String, Integer> entry : map.entrySet()) {
final String key = entry.getKey();
final Integer temp = entry.getValue();
if (StrUtil.isBlank(max) || temp > num) {
max = key;
num = temp;
}
}
String[] strings = max.split("-");
final String[] strings = max.split("-");
// rgb 的数量只有3个
int rgbLength = 3;
final int rgbLength = 3;
if (strings.length == rgbLength) {
return ImgUtil.toHex(Integer.parseInt(strings[0]), Integer.parseInt(strings[1]),
Integer.parseInt(strings[2]));
@@ -339,12 +339,12 @@ public class BackgroundRemoval {
* @param imagesType 文件包含的类型数组
* @return 返回布尔值 false:给定文件的文件类型在文件数组中 true:给定文件的文件类型 不在给定数组中。
*/
private static boolean fileTypeValidation(File input, String[] imagesType) {
private static boolean fileTypeValidation(final File input, final String[] imagesType) {
if (!input.exists()) {
throw new IllegalArgumentException("给定文件为空");
}
// 获取图片类型
String type = FileTypeUtil.getType(input);
final String type = FileTypeUtil.getType(input);
// 类型对比
if (!ArrayUtil.contains(imagesType, type)) {
throw new IllegalArgumentException(StrUtil.format("文件类型{}不支持", type));

View File

@@ -34,7 +34,7 @@ public class FontUtil {
* @param size 字体大小
* @return 字体
*/
public static Font createSansSerifFont(int size) {
public static Font createSansSerifFont(final int size) {
return createFont(Font.SANS_SERIF, size);
}
@@ -45,7 +45,7 @@ public class FontUtil {
* @param size 字体大小
* @return 字体
*/
public static Font createFont(String name, int size) {
public static Font createFont(final String name, final int size) {
return new Font(name, Font.PLAIN, size);
}
@@ -56,17 +56,17 @@ public class FontUtil {
* @param fontFile 字体文件
* @return {@link Font}
*/
public static Font createFont(File fontFile) {
public static Font createFont(final File fontFile) {
try {
return Font.createFont(Font.TRUETYPE_FONT, fontFile);
} catch (FontFormatException e) {
} catch (final FontFormatException e) {
// True Type字体无效时使用Type1字体
try {
return Font.createFont(Font.TYPE1_FONT, fontFile);
} catch (Exception e1) {
} catch (final Exception e1) {
throw new UtilException(e);
}
} catch (IOException e) {
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
@@ -78,17 +78,17 @@ public class FontUtil {
* @param fontStream 字体流
* @return {@link Font}
*/
public static Font createFont(InputStream fontStream) {
public static Font createFont(final InputStream fontStream) {
try {
return Font.createFont(Font.TRUETYPE_FONT, fontStream);
} catch (FontFormatException e) {
} catch (final FontFormatException e) {
// True Type字体无效时使用Type1字体
try {
return Font.createFont(Font.TYPE1_FONT, fontStream);
} catch (Exception e1) {
} catch (final Exception e1) {
throw new UtilException(e1);
}
} catch (IOException e) {
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
@@ -100,7 +100,7 @@ public class FontUtil {
* @param str 字符串
* @return 长宽信息
*/
public static Dimension getDimension(FontMetrics metrics, String str) {
public static Dimension getDimension(final FontMetrics metrics, final String str) {
final int width = metrics.stringWidth(str);
final int height = metrics.getAscent() - metrics.getLeading() - metrics.getDescent();

View File

@@ -31,7 +31,7 @@ public class GraphicsUtil {
* @return {@link Graphics2D}
* @since 4.5.2
*/
public static Graphics2D createGraphics(BufferedImage image, Color color) {
public static Graphics2D createGraphics(final BufferedImage image, final Color color) {
final Graphics2D g = image.createGraphics();
if (null != color) {
@@ -52,15 +52,15 @@ public class GraphicsUtil {
* @return 最小高度,-1表示无法获取
* @since 4.5.17
*/
public static int getCenterY(Graphics g, int backgroundHeight) {
public static int getCenterY(final Graphics g, final int backgroundHeight) {
// 获取允许文字最小高度
FontMetrics metrics = null;
try {
metrics = g.getFontMetrics();
} catch (Exception e) {
} catch (final Exception e) {
// 此处报告bug某些情况下会抛出IndexOutOfBoundsException在此做容错处理
}
int y;
final int y;
if (null != metrics) {
y = (backgroundHeight - metrics.getHeight()) / 2 + metrics.getAscent();
} else {
@@ -80,7 +80,7 @@ public class GraphicsUtil {
* @return 画笔对象
* @since 4.5.10
*/
public static Graphics drawStringColourful(Graphics g, String str, Font font, int width, int height) {
public static Graphics drawStringColourful(final Graphics g, final String str, final Font font, final int width, final int height) {
return drawString(g, str, font, null, width, height);
}
@@ -96,7 +96,7 @@ public class GraphicsUtil {
* @return 画笔对象
* @since 4.5.10
*/
public static Graphics drawString(Graphics g, String str, Font font, Color color, int width, int height) {
public static Graphics drawString(final Graphics g, final String str, final Font font, final Color color, final int width, final int height) {
// 抗锯齿
if (g instanceof Graphics2D) {
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@@ -105,13 +105,13 @@ public class GraphicsUtil {
g.setFont(font);
// 文字高度(必须在设置字体后调用)
int midY = getCenterY(g, height);
final int midY = getCenterY(g, height);
if (null != color) {
g.setColor(color);
}
final int len = str.length();
int charWidth = width / len;
final int charWidth = width / len;
for (int i = 0; i < len; i++) {
if (null == color) {
// 产生随机的颜色值,让输出的每个字符的颜色值都将不同。
@@ -134,7 +134,7 @@ public class GraphicsUtil {
* @return 画笔对象
* @since 4.5.10
*/
public static Graphics drawString(Graphics g, String str, Font font, Color color, Rectangle rectangle) {
public static Graphics drawString(final Graphics g, final String str, final Font font, final Color color, final Rectangle rectangle) {
// 背景长宽
final int backgroundWidth = rectangle.width;
final int backgroundHeight = rectangle.height;
@@ -143,7 +143,7 @@ public class GraphicsUtil {
Dimension dimension;
try {
dimension = FontUtil.getDimension(g.getFontMetrics(font), str);
} catch (Exception e) {
} catch (final Exception e) {
// 此处报告bug某些情况下会抛出IndexOutOfBoundsException在此做容错处理
dimension = new Dimension(backgroundWidth / 3, backgroundHeight / 3);
}
@@ -165,7 +165,7 @@ public class GraphicsUtil {
* @return 画笔对象
* @since 5.3.6
*/
public static Graphics drawString(Graphics g, String str, Font font, Color color, Point point) {
public static Graphics drawString(final Graphics g, final String str, final Font font, final Color color, final Point point) {
// 抗锯齿
if (g instanceof Graphics2D) {
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@@ -186,7 +186,7 @@ public class GraphicsUtil {
* @param point 绘制的位置,基于左上角
* @return 画笔对象
*/
public static Graphics drawImg(Graphics g, Image img, Point point) {
public static Graphics drawImg(final Graphics g, final Image img, final Point point) {
return drawImg(g, img,
new Rectangle(point.x, point.y, img.getWidth(null), img.getHeight(null)));
}
@@ -199,7 +199,7 @@ public class GraphicsUtil {
* @param rectangle 矩形对象表示矩形区域的xywidthheight,,基于左上角
* @return 画笔对象
*/
public static Graphics drawImg(Graphics g, Image img, Rectangle rectangle) {
public static Graphics drawImg(final Graphics g, final Image img, final Rectangle rectangle) {
g.drawImage(img, rectangle.x, rectangle.y, rectangle.width, rectangle.height, null); // 绘制切割后的图
return g;
}
@@ -211,7 +211,7 @@ public class GraphicsUtil {
* @param alpha 透明度alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
* @return 画笔
*/
public static Graphics2D setAlpha(Graphics2D g, float alpha){
public static Graphics2D setAlpha(final Graphics2D g, final float alpha){
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
return g;
}

View File

@@ -67,7 +67,7 @@ public class Img implements Serializable {
* @param imagePath 图片文件路径
* @return Img
*/
public static Img from(Path imagePath) {
public static Img from(final Path imagePath) {
return from(imagePath.toFile());
}
@@ -77,7 +77,7 @@ public class Img implements Serializable {
* @param imageFile 图片文件
* @return Img
*/
public static Img from(File imageFile) {
public static Img from(final File imageFile) {
return new Img(ImgUtil.read(imageFile));
}
@@ -88,7 +88,7 @@ public class Img implements Serializable {
* @return Img
* @since 4.4.1
*/
public static Img from(Resource resource) {
public static Img from(final Resource resource) {
return from(resource.getStream());
}
@@ -98,7 +98,7 @@ public class Img implements Serializable {
* @param in 图片流
* @return Img
*/
public static Img from(InputStream in) {
public static Img from(final InputStream in) {
return new Img(ImgUtil.read(in));
}
@@ -108,7 +108,7 @@ public class Img implements Serializable {
* @param imageStream 图片流
* @return Img
*/
public static Img from(ImageInputStream imageStream) {
public static Img from(final ImageInputStream imageStream) {
return new Img(ImgUtil.read(imageStream));
}
@@ -118,7 +118,7 @@ public class Img implements Serializable {
* @param imageUrl 图片URL
* @return Img
*/
public static Img from(URL imageUrl) {
public static Img from(final URL imageUrl) {
return new Img(ImgUtil.read(imageUrl));
}
@@ -128,7 +128,7 @@ public class Img implements Serializable {
* @param image 图片
* @return Img
*/
public static Img from(Image image) {
public static Img from(final Image image) {
return new Img(ImgUtil.toBufferedImage(image));
}
@@ -137,7 +137,7 @@ public class Img implements Serializable {
*
* @param srcImage 来源图片
*/
public Img(BufferedImage srcImage) {
public Img(final BufferedImage srcImage) {
this(srcImage, null);
}
@@ -148,7 +148,7 @@ public class Img implements Serializable {
* @param targetImageType 目标图片类型null则读取来源图片类型
* @since 5.0.7
*/
public Img(BufferedImage srcImage, String targetImageType) {
public Img(final BufferedImage srcImage, String targetImageType) {
this.srcImage = srcImage;
if (null == targetImageType) {
if (srcImage.getType() == BufferedImage.TYPE_INT_ARGB
@@ -172,7 +172,7 @@ public class Img implements Serializable {
* @see ImgUtil#IMAGE_TYPE_JPG
* @see ImgUtil#IMAGE_TYPE_PNG
*/
public Img setTargetImageType(String imgType) {
public Img setTargetImageType(final String imgType) {
this.targetImageType = imgType;
return this;
}
@@ -184,7 +184,7 @@ public class Img implements Serializable {
* @return this
* @since 4.1.15
*/
public Img setPositionBaseCentre(boolean positionBaseCentre) {
public Img setPositionBaseCentre(final boolean positionBaseCentre) {
this.positionBaseCentre = positionBaseCentre;
return this;
}
@@ -196,7 +196,7 @@ public class Img implements Serializable {
* @return this
* @since 4.3.2
*/
public Img setQuality(double quality) {
public Img setQuality(final double quality) {
return setQuality((float) quality);
}
@@ -207,7 +207,7 @@ public class Img implements Serializable {
* @return this
* @since 4.3.2
*/
public Img setQuality(float quality) {
public Img setQuality(final float quality) {
if (quality > 0 && quality < 1) {
this.quality = quality;
} else {
@@ -253,7 +253,7 @@ public class Img implements Serializable {
* @param height 目标高度
* @return this
*/
public Img scale(int width, int height) {
public Img scale(final int width, final int height) {
return scale(width, height, Image.SCALE_SMOOTH);
}
@@ -267,11 +267,11 @@ public class Img implements Serializable {
* @return this
* @since 5.7.18
*/
public Img scale(int width, int height, int scaleType) {
public Img scale(final int width, final int height, final int scaleType) {
final Image srcImg = getValidSrcImg();
int srcHeight = srcImg.getHeight(null);
int srcWidth = srcImg.getWidth(null);
final int srcHeight = srcImg.getHeight(null);
final int srcWidth = srcImg.getWidth(null);
if (srcHeight == height && srcWidth == width) {
// 源与目标长宽一致返回原图
this.targetImage = srcImg;
@@ -300,12 +300,12 @@ public class Img implements Serializable {
* @param fixedColor 比例不对时补充的颜色,不补充为{@code null}
* @return this
*/
public Img scale(int width, int height, Color fixedColor) {
public Img scale(final int width, final int height, final Color fixedColor) {
Image srcImage = getValidSrcImg();
int srcHeight = srcImage.getHeight(null);
int srcWidth = srcImage.getWidth(null);
double heightRatio = NumberUtil.div(height, srcHeight);
double widthRatio = NumberUtil.div(width, srcWidth);
final double heightRatio = NumberUtil.div(height, srcHeight);
final double widthRatio = NumberUtil.div(width, srcWidth);
// 浮点数之间的等值判断,基本数据类型不能用==比较,包装数据类型不能用equals来判断。
if (NumberUtil.equals(heightRatio, widthRatio)) {
@@ -325,7 +325,7 @@ public class Img implements Serializable {
srcWidth = srcImage.getWidth(null);
final BufferedImage image = new BufferedImage(width, height, getTypeInt());
Graphics2D g = image.createGraphics();
final Graphics2D g = image.createGraphics();
// 设置背景
if (null != fixedColor) {
@@ -347,7 +347,7 @@ public class Img implements Serializable {
* @param rectangle 矩形对象表示矩形区域的xywidthheight
* @return this
*/
public Img cut(Rectangle rectangle) {
public Img cut(final Rectangle rectangle) {
final Image srcImage = getValidSrcImg();
fixRectangle(rectangle, srcImage.getWidth(null), srcImage.getHeight(null));
@@ -364,7 +364,7 @@ public class Img implements Serializable {
* @return this
* @since 4.1.15
*/
public Img cut(int x, int y) {
public Img cut(final int x, final int y) {
return cut(x, y, -1);
}
@@ -377,7 +377,7 @@ public class Img implements Serializable {
* @return this
* @since 4.1.15
*/
public Img cut(int x, int y, int radius) {
public Img cut(int x, int y, final int radius) {
final Image srcImage = getValidSrcImg();
final int width = srcImage.getWidth(null);
final int height = srcImage.getHeight(null);
@@ -458,7 +458,7 @@ public class Img implements Serializable {
* @param alpha 透明度alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
* @return 处理后的图像
*/
public Img pressText(String pressText, Color color, Font font, int x, int y, float alpha) {
public Img pressText(final String pressText, final Color color, final Font font, final int x, final int y, final float alpha) {
return pressText(pressText, color, font, new Point(x, y), alpha);
}
@@ -473,7 +473,7 @@ public class Img implements Serializable {
* @param alpha 透明度alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
* @return 处理后的图像
*/
public Img pressText(String pressText, Color color, Font font, Point point, float alpha) {
public Img pressText(final String pressText, final Color color, Font font, final Point point, final float alpha) {
final BufferedImage targetImage = ImgUtil.toBufferedImage(getValidSrcImg(), this.targetImageType);
if (null == font) {
@@ -515,7 +515,7 @@ public class Img implements Serializable {
* @return 处理后的图像
* @since 5.8.0
*/
public Img pressTextFull(String pressText, Color color, Font font, int lineHeight, int degree, float alpha) {
public Img pressTextFull(final String pressText, final Color color, Font font, final int lineHeight, final int degree, final float alpha) {
final BufferedImage targetImage = ImgUtil.toBufferedImage(getValidSrcImg(), this.targetImageType);
if (null == font) {
@@ -536,7 +536,7 @@ public class Img implements Serializable {
Dimension dimension;
try {
dimension = FontUtil.getDimension(g.getFontMetrics(font), pressText);
} catch (Exception e) {
} catch (final Exception e) {
// 此处报告bug某些情况下会抛出IndexOutOfBoundsException在此做容错处理
dimension = new Dimension(targetWidth / 3, targetHeight / 3);
}
@@ -566,7 +566,7 @@ public class Img implements Serializable {
* @param alpha 透明度alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
* @return this
*/
public Img pressImage(Image pressImg, int x, int y, float alpha) {
public Img pressImage(final Image pressImg, final int x, final int y, final float alpha) {
final int pressImgWidth = pressImg.getWidth(null);
final int pressImgHeight = pressImg.getHeight(null);
return pressImage(pressImg, new Rectangle(x, y, pressImgWidth, pressImgHeight), alpha);
@@ -581,7 +581,7 @@ public class Img implements Serializable {
* @return this
* @since 4.1.14
*/
public Img pressImage(Image pressImg, Rectangle rectangle, float alpha) {
public Img pressImage(final Image pressImg, final Rectangle rectangle, final float alpha) {
final Image targetImg = getValidSrcImg();
this.targetImage = draw(ImgUtil.toBufferedImage(targetImg, this.targetImageType), pressImg, rectangle, alpha);
@@ -596,13 +596,13 @@ public class Img implements Serializable {
* @return 旋转后的图片
* @since 3.2.2
*/
public Img rotate(int degree) {
public Img rotate(final int degree) {
final Image image = getValidSrcImg();
int width = image.getWidth(null);
int height = image.getHeight(null);
final int width = image.getWidth(null);
final int height = image.getHeight(null);
final Rectangle rectangle = calcRotatedSize(width, height, degree);
final BufferedImage targetImg = new BufferedImage(rectangle.width, rectangle.height, getTypeInt());
Graphics2D graphics2d = targetImg.createGraphics();
final Graphics2D graphics2d = targetImg.createGraphics();
// 抗锯齿
graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
// 从中心旋转
@@ -621,10 +621,10 @@ public class Img implements Serializable {
*/
public Img flip() {
final Image image = getValidSrcImg();
int width = image.getWidth(null);
int height = image.getHeight(null);
final int width = image.getWidth(null);
final int height = image.getHeight(null);
final BufferedImage targetImg = new BufferedImage(width, height, getTypeInt());
Graphics2D graphics2d = targetImg.createGraphics();
final Graphics2D graphics2d = targetImg.createGraphics();
graphics2d.drawImage(image, 0, 0, width, height, width, 0, 0, height, null);
graphics2d.dispose();
@@ -640,7 +640,7 @@ public class Img implements Serializable {
* @return this
* @since 5.4.1
*/
public Img stroke(Color color, float width) {
public Img stroke(final Color color, final float width) {
return stroke(color, new BasicStroke(width));
}
@@ -652,11 +652,11 @@ public class Img implements Serializable {
* @return this
* @since 5.4.1
*/
public Img stroke(Color color, Stroke stroke) {
public Img stroke(final Color color, final Stroke stroke) {
final BufferedImage image = ImgUtil.toBufferedImage(getValidSrcImg(), this.targetImageType);
int width = image.getWidth(null);
int height = image.getHeight(null);
Graphics2D g = image.createGraphics();
final int width = image.getWidth(null);
final int height = image.getHeight(null);
final Graphics2D g = image.createGraphics();
g.setColor(ObjUtil.defaultIfNull(color, Color.BLACK));
if (null != stroke) {
@@ -690,7 +690,7 @@ public class Img implements Serializable {
* @return 是否成功写出如果返回false表示未找到合适的Writer
* @throws IORuntimeException IO异常
*/
public boolean write(OutputStream out) throws IORuntimeException {
public boolean write(final OutputStream out) throws IORuntimeException {
return write(ImgUtil.getImageOutputStream(out));
}
@@ -702,7 +702,7 @@ public class Img implements Serializable {
* @return 是否成功写出如果返回false表示未找到合适的Writer
* @throws IORuntimeException IO异常
*/
public boolean write(ImageOutputStream targetImageStream) throws IORuntimeException {
public boolean write(final ImageOutputStream targetImageStream) throws IORuntimeException {
Assert.notBlank(this.targetImageType, "Target image type is blank !");
Assert.notNull(targetImageStream, "Target output stream is null !");
@@ -719,7 +719,7 @@ public class Img implements Serializable {
* @return 是否成功写出如果返回false表示未找到合适的Writer
* @throws IORuntimeException IO异常
*/
public boolean write(File targetFile) throws IORuntimeException {
public boolean write(final File targetFile) throws IORuntimeException {
final String formatName = FileUtil.extName(targetFile);
if (StrUtil.isNotBlank(formatName)) {
this.targetImageType = formatName;
@@ -750,7 +750,7 @@ public class Img implements Serializable {
* @param alpha 透明度alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
* @return 绘制后的背景
*/
private BufferedImage draw(BufferedImage backgroundImg, Image img, Rectangle rectangle, float alpha) {
private BufferedImage draw(final BufferedImage backgroundImg, final Image img, final Rectangle rectangle, final float alpha) {
final Graphics2D g = backgroundImg.createGraphics();
GraphicsUtil.setAlpha(g, alpha);
@@ -807,7 +807,7 @@ public class Img implements Serializable {
* @return 修正后的{@link Rectangle}
* @since 4.1.15
*/
private Rectangle fixRectangle(Rectangle rectangle, int baseWidth, int baseHeight) {
private Rectangle fixRectangle(final Rectangle rectangle, final int baseWidth, final int baseHeight) {
if (this.positionBaseCentre) {
final Point pointBaseCentre = ImgUtil.getPointBaseCentre(rectangle, baseWidth, baseHeight);
// 修正图片位置从背景的中心计算
@@ -832,22 +832,22 @@ public class Img implements Serializable {
}
if (degree >= 90) {
if (degree / 90 % 2 == 1) {
int temp = height;
final int temp = height;
//noinspection SuspiciousNameCombination
height = width;
width = temp;
}
degree = degree % 90;
}
double r = Math.sqrt(height * height + width * width) / 2;
double len = 2 * Math.sin(Math.toRadians(degree) / 2) * r;
double angel_alpha = (Math.PI - Math.toRadians(degree)) / 2;
double angel_dalta_width = Math.atan((double) height / width);
double angel_dalta_height = Math.atan((double) width / height);
int len_dalta_width = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_width));
int len_dalta_height = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_height));
int des_width = width + len_dalta_width * 2;
int des_height = height + len_dalta_height * 2;
final double r = Math.sqrt(height * height + width * width) / 2;
final double len = 2 * Math.sin(Math.toRadians(degree) / 2) * r;
final double angel_alpha = (Math.PI - Math.toRadians(degree)) / 2;
final double angel_dalta_width = Math.atan((double) height / width);
final double angel_dalta_height = Math.atan((double) width / height);
final int len_dalta_width = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_width));
final int len_dalta_height = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_height));
final int des_width = width + len_dalta_width * 2;
final int des_height = height + len_dalta_height * 2;
return new Rectangle(des_width, des_height);
}

File diff suppressed because it is too large Load Diff

View File

@@ -31,7 +31,7 @@ public enum ScaleType {
* @see Image#SCALE_REPLICATE
* @see Image#SCALE_AREA_AVERAGING
*/
ScaleType(int value) {
ScaleType(final int value) {
this.value = value;
}

View File

@@ -61,7 +61,7 @@ public class AnimatedGifEncoder {
*
* @param ms 间隔时间,单位毫秒
*/
public void setDelay(int ms) {
public void setDelay(final int ms) {
delay = Math.round(ms / 10.0f);
}
@@ -72,7 +72,7 @@ public class AnimatedGifEncoder {
*
* @param code int disposal code.
*/
public void setDispose(int code) {
public void setDispose(final int code) {
if (code >= 0) {
dispose = code;
}
@@ -86,7 +86,7 @@ public class AnimatedGifEncoder {
*
* @param iter int number of iterations.
*/
public void setRepeat(int iter) {
public void setRepeat(final int iter) {
if (iter >= 0) {
repeat = iter;
}
@@ -103,7 +103,7 @@ public class AnimatedGifEncoder {
*
* @param c Color to be treated as transparent on display.
*/
public void setTransparent(Color c) {
public void setTransparent(final Color c) {
setTransparent(c, false);
}
@@ -122,7 +122,7 @@ public class AnimatedGifEncoder {
* @param c Color to be treated as transparent on display.
* @param exactMatch If exactMatch is set to true, transparent color index is search with exact match
*/
public void setTransparent(Color c, boolean exactMatch) {
public void setTransparent(final Color c, final boolean exactMatch) {
transparent = c;
transparentExactMatch = exactMatch;
}
@@ -140,7 +140,7 @@ public class AnimatedGifEncoder {
*
* @param c Color to be treated as background on display.
*/
public void setBackground(Color c) {
public void setBackground(final Color c) {
background = c;
}
@@ -154,7 +154,7 @@ public class AnimatedGifEncoder {
* @param im BufferedImage containing frame to write.
* @return true if successful.
*/
public boolean addFrame(BufferedImage im) {
public boolean addFrame(final BufferedImage im) {
if ((im == null) || !started) {
return false;
}
@@ -182,7 +182,7 @@ public class AnimatedGifEncoder {
}
writePixels(); // encode and write pixel data
firstFrame = false;
} catch (IOException e) {
} catch (final IOException e) {
ok = false;
}
@@ -206,7 +206,7 @@ public class AnimatedGifEncoder {
if (closeStream) {
out.close();
}
} catch (IOException e) {
} catch (final IOException e) {
ok = false;
}
@@ -229,7 +229,7 @@ public class AnimatedGifEncoder {
*
* @param fps float frame rate (frames per second)
*/
public void setFrameRate(float fps) {
public void setFrameRate(final float fps) {
if (fps != 0f) {
delay = Math.round(100f / fps);
}
@@ -258,7 +258,7 @@ public class AnimatedGifEncoder {
* @param w int frame width.
* @param h int frame width.
*/
public void setSize(int w, int h) {
public void setSize(final int w, final int h) {
if (started && !firstFrame) return;
width = w;
height = h;
@@ -274,14 +274,14 @@ public class AnimatedGifEncoder {
* @param os OutputStream on which GIF images are written.
* @return false if initial write failed.
*/
public boolean start(OutputStream os) {
public boolean start(final OutputStream os) {
if (os == null) return false;
boolean ok = true;
closeStream = false;
out = os;
try {
writeString("GIF89a"); // header
} catch (IOException e) {
} catch (final IOException e) {
ok = false;
}
return started = ok;
@@ -293,13 +293,13 @@ public class AnimatedGifEncoder {
* @param file String containing output file name.
* @return false if open or initial write failed.
*/
public boolean start(String file) {
public boolean start(final String file) {
boolean ok;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
ok = start(out);
closeStream = true;
} catch (IOException e) {
} catch (final IOException e) {
ok = false;
}
return started = ok;
@@ -313,15 +313,15 @@ public class AnimatedGifEncoder {
* Analyzes image colors and creates color map.
*/
protected void analyzePixels() {
int len = pixels.length;
int nPix = len / 3;
final int len = pixels.length;
final int nPix = len / 3;
indexedPixels = new byte[nPix];
NeuQuant nq = new NeuQuant(pixels, len, sample);
final NeuQuant nq = new NeuQuant(pixels, len, sample);
// initialize quantizer
colorTab = nq.process(); // create reduced palette
// convert map from BGR to RGB
for (int i = 0; i < colorTab.length; i += 3) {
byte temp = colorTab[i];
final byte temp = colorTab[i];
colorTab[i] = colorTab[i + 2];
colorTab[i + 2] = temp;
usedEntry[i / 3] = false;
@@ -329,7 +329,7 @@ public class AnimatedGifEncoder {
// map image pixels to new palette
int k = 0;
for (int i = 0; i < nPix; i++) {
int index =
final int index =
nq.map(pixels[k++] & 0xff,
pixels[k++] & 0xff,
pixels[k++] & 0xff);
@@ -351,20 +351,20 @@ public class AnimatedGifEncoder {
* @param c Color
* @return index
*/
protected int findClosest(Color c) {
protected int findClosest(final Color c) {
if (colorTab == null) return -1;
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
final int r = c.getRed();
final int g = c.getGreen();
final int b = c.getBlue();
int minpos = 0;
int dmin = 256 * 256 * 256;
int len = colorTab.length;
final int len = colorTab.length;
for (int i = 0; i < len; ) {
int dr = r - (colorTab[i++] & 0xff);
int dg = g - (colorTab[i++] & 0xff);
int db = b - (colorTab[i] & 0xff);
int d = dr * dr + dg * dg + db * db;
int index = i / 3;
final int dr = r - (colorTab[i++] & 0xff);
final int dg = g - (colorTab[i++] & 0xff);
final int db = b - (colorTab[i] & 0xff);
final int d = dr * dr + dg * dg + db * db;
final int index = i / 3;
if (usedEntry[index] && (d < dmin)) {
dmin = d;
minpos = index;
@@ -382,7 +382,7 @@ public class AnimatedGifEncoder {
* @param c 颜色
* @return 颜色是否存在
*/
boolean isColorUsed(Color c) {
boolean isColorUsed(final Color c) {
return findExact(c) != -1;
}
@@ -392,17 +392,17 @@ public class AnimatedGifEncoder {
* @param c Color
* @return index
*/
protected int findExact(Color c) {
protected int findExact(final Color c) {
if (colorTab == null) {
return -1;
}
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
int len = colorTab.length / 3;
final int r = c.getRed();
final int g = c.getGreen();
final int b = c.getBlue();
final int len = colorTab.length / 3;
for (int index = 0; index < len; ++index) {
int i = index * 3;
final int i = index * 3;
// If the entry is used in colorTab, then check if it is the same exact color we're looking for
if (usedEntry[index] && r == (colorTab[i] & 0xff) && g == (colorTab[i + 1] & 0xff) && b == (colorTab[i + 2] & 0xff)) {
return index;
@@ -415,16 +415,16 @@ public class AnimatedGifEncoder {
* Extracts image pixels into byte array "pixels"
*/
protected void getImagePixels() {
int w = image.getWidth();
int h = image.getHeight();
int type = image.getType();
final int w = image.getWidth();
final int h = image.getHeight();
final int type = image.getType();
if ((w != width)
|| (h != height)
|| (type != BufferedImage.TYPE_3BYTE_BGR)) {
// create new image with right size/format
BufferedImage temp =
final BufferedImage temp =
new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = temp.createGraphics();
final Graphics2D g = temp.createGraphics();
g.setColor(background);
g.fillRect(0, 0, width, height);
g.drawImage(image, 0, 0, null);
@@ -442,7 +442,8 @@ public class AnimatedGifEncoder {
out.write(0x21); // extension introducer
out.write(0xf9); // GCE label
out.write(4); // data block size
int transp, disp;
final int transp;
int disp;
if (transparent == null) {
transp = 0;
disp = 0; // dispose = no action
@@ -537,7 +538,7 @@ public class AnimatedGifEncoder {
*/
protected void writePalette() throws IOException {
out.write(colorTab, 0, colorTab.length);
int n = (3 * 256) - colorTab.length;
final int n = (3 * 256) - colorTab.length;
for (int i = 0; i < n; i++) {
out.write(0);
}
@@ -549,7 +550,7 @@ public class AnimatedGifEncoder {
* @throws IOException IO异常
*/
protected void writePixels() throws IOException {
LZWEncoder encoder = new LZWEncoder(width, height, indexedPixels, colorDepth);
final LZWEncoder encoder = new LZWEncoder(width, height, indexedPixels, colorDepth);
encoder.encode(out);
}
@@ -559,7 +560,7 @@ public class AnimatedGifEncoder {
* @param value 16-bit value
* @throws IOException IO异常
*/
protected void writeShort(int value) throws IOException {
protected void writeShort(final int value) throws IOException {
out.write(value & 0xff);
out.write((value >> 8) & 0xff);
}
@@ -570,7 +571,7 @@ public class AnimatedGifEncoder {
* @param s String
* @throws IOException IO异常
*/
protected void writeString(String s) throws IOException {
protected void writeString(final String s) throws IOException {
for (int i = 0; i < s.length(); i++) {
out.write((byte) s.charAt(i));
}

View File

@@ -107,7 +107,7 @@ public class GifDecoder {
protected int frameCount;
static class GifFrame {
public GifFrame(BufferedImage im, int del) {
public GifFrame(final BufferedImage im, final int del) {
image = im;
delay = del;
}
@@ -122,7 +122,7 @@ public class GifDecoder {
* @param n int index of frame
* @return delay in milliseconds
*/
public int getDelay(int n) {
public int getDelay(final int n) {
//
delay = -1;
if ((n >= 0) && (n < frameCount)) {
@@ -165,14 +165,14 @@ public class GifDecoder {
*/
protected void setPixels() {
// expose destination image's pixels as int array
int[] dest =
final int[] dest =
((DataBufferInt) image.getRaster().getDataBuffer()).getData();
// fill in starting image contents based on last image's dispose code
if (lastDispose > 0) {
if (lastDispose == 3) {
// use image before last
int n = frameCount - 2;
final int n = frameCount - 2;
if (n > 0) {
lastImage = getFrame(n - 1);
} else {
@@ -181,15 +181,15 @@ public class GifDecoder {
}
if (lastImage != null) {
int[] prev =
final int[] prev =
((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();
System.arraycopy(prev, 0, dest, 0, width * height);
// copy pixels
if (lastDispose == 2) {
// fill last image rect area with background color
Graphics2D g = image.createGraphics();
Color c;
final Graphics2D g = image.createGraphics();
final Color c;
if (transparency) {
c = new Color(0, 0, 0, 0); // assume background is transparent
} else {
@@ -230,7 +230,7 @@ public class GifDecoder {
}
line += iy;
if (line < height) {
int k = line * width;
final int k = line * width;
int dx = k + ix; // start of line in dest
int dlim = dx + iw; // end of dest line
if ((k + width) < dlim) {
@@ -239,8 +239,8 @@ public class GifDecoder {
int sx = i * iw; // start of line in source
while (dx < dlim) {
// map color and insert in destination
int index = ((int) pixels[sx++]) & 0xff;
int c = act[index];
final int index = ((int) pixels[sx++]) & 0xff;
final int c = act[index];
if (c != 0) {
dest[dx] = c;
}
@@ -256,7 +256,7 @@ public class GifDecoder {
* @param n frame
* @return BufferedImage
*/
public BufferedImage getFrame(int n) {
public BufferedImage getFrame(final int n) {
BufferedImage im = null;
if ((n >= 0) && (n < frameCount)) {
im = frames.get(n).image;
@@ -279,7 +279,7 @@ public class GifDecoder {
* @param is BufferedInputStream containing GIF file.
* @return read status code (0 = no errors)
*/
public int read(BufferedInputStream is) {
public int read(final BufferedInputStream is) {
init();
if (is != null) {
in = is;
@@ -336,13 +336,13 @@ public class GifDecoder {
name = name.trim().toLowerCase();
if ((name.contains("file:")) ||
(name.indexOf(":/") > 0)) {
URL url = new URL(name);
final URL url = new URL(name);
in = new BufferedInputStream(url.openStream());
} else {
in = new BufferedInputStream(new FileInputStream(name));
}
status = read(in);
} catch (IOException e) {
} catch (final IOException e) {
status = STATUS_OPEN_ERROR;
}
@@ -354,25 +354,25 @@ public class GifDecoder {
* Adapted from John Cristy's ImageMagick.
*/
protected void decodeImageData() {
int NullCode = -1;
int npix = iw * ih;
int available,
clear,
code_mask,
code_size,
end_of_information,
in_code,
old_code,
bits,
code,
count,
i,
datum,
data_size,
first,
top,
bi,
pi;
final int NullCode = -1;
final int npix = iw * ih;
int available;
int clear;
int code_mask;
int code_size;
int end_of_information;
int in_code;
int old_code;
int bits;
int code;
int count;
int i;
int datum;
final int data_size;
int first;
int top;
int bi;
int pi;
if ((pixels == null) || (pixels.length < npix)) {
pixels = new byte[npix]; // allocate new pixel array
@@ -512,7 +512,7 @@ public class GifDecoder {
int curByte = 0;
try {
curByte = in.read();
} catch (IOException e) {
} catch (final IOException e) {
status = STATUS_FORMAT_ERROR;
}
return curByte;
@@ -535,7 +535,7 @@ public class GifDecoder {
break;
n += count;
}
} catch (IOException e) {
} catch (final IOException e) {
//ignore
}
@@ -552,14 +552,14 @@ public class GifDecoder {
* @param ncolors int number of colors to read
* @return int array containing 256 colors (packed ARGB with full alpha)
*/
protected int[] readColorTable(int ncolors) {
int nbytes = 3 * ncolors;
protected int[] readColorTable(final int ncolors) {
final int nbytes = 3 * ncolors;
int[] tab = null;
byte[] c = new byte[nbytes];
final byte[] c = new byte[nbytes];
int n = 0;
try {
n = in.read(c);
} catch (IOException e) {
} catch (final IOException e) {
//ignore
}
if (n < nbytes) {
@@ -569,9 +569,9 @@ public class GifDecoder {
int i = 0;
int j = 0;
while (i < ncolors) {
int r = ((int) c[j++]) & 0xff;
int g = ((int) c[j++]) & 0xff;
int b = ((int) c[j++]) & 0xff;
final int r = ((int) c[j++]) & 0xff;
final int g = ((int) c[j++]) & 0xff;
final int b = ((int) c[j++]) & 0xff;
tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
@@ -635,7 +635,7 @@ public class GifDecoder {
*/
protected void readGraphicControlExt() {
read(); // block size
int packed = read(); // packed fields
final int packed = read(); // packed fields
dispose = (packed & 0x1c) >> 2; // disposal method
if (dispose == 0) {
dispose = 1; // elect to keep old image if discretionary
@@ -675,7 +675,7 @@ public class GifDecoder {
iw = readShort();
ih = readShort();
int packed = read();
final int packed = read();
lctFlag = (packed & 0x80) != 0; // 1 - local color table flag
interlace = (packed & 0x40) != 0; // 2 - interlace flag
// 3 - sort flag
@@ -734,7 +734,7 @@ public class GifDecoder {
height = readShort();
// packed fields
int packed = read();
final int packed = read();
gctFlag = (packed & 0x80) != 0; // 1 : global color table flag
// 2-4 : color resolution
// 5 : gct sort flag
@@ -752,8 +752,8 @@ public class GifDecoder {
readBlock();
if (block[0] == 1) {
// loop count sub-block
int b1 = ((int) block[1]) & 0xff;
int b2 = ((int) block[2]) & 0xff;
final int b1 = ((int) block[1]) & 0xff;
final int b2 = ((int) block[2]) & 0xff;
loopCount = (b2 << 8) | b1;
}
} while ((blockSize > 0) && !err());

View File

@@ -119,7 +119,7 @@ class LZWEncoder {
byte[] accum = new byte[256];
//----------------------------------------------------------------------------
LZWEncoder(int width, int height, byte[] pixels, int color_depth) {
LZWEncoder(final int width, final int height, final byte[] pixels, final int color_depth) {
imgW = width;
imgH = height;
pixAry = pixels;
@@ -128,7 +128,7 @@ class LZWEncoder {
// Add a character to the end of the current packet, and if it is 254
// characters, flush the packet to disk.
void char_out(byte c, OutputStream outs) throws IOException {
void char_out(final byte c, final OutputStream outs) throws IOException {
accum[a_count++] = c;
if (a_count >= 254)
flush_char(outs);
@@ -137,7 +137,7 @@ class LZWEncoder {
// Clear out the hash table
// table clear for block compress
void cl_block(OutputStream outs) throws IOException {
void cl_block(final OutputStream outs) throws IOException {
cl_hash(hsize);
free_ent = ClearCode + 2;
clear_flg = true;
@@ -146,18 +146,18 @@ class LZWEncoder {
}
// reset code table
void cl_hash(int hsize) {
void cl_hash(final int hsize) {
for (int i = 0; i < hsize; ++i)
htab[i] = -1;
}
void compress(int init_bits, OutputStream outs) throws IOException {
void compress(final int init_bits, final OutputStream outs) throws IOException {
int fcode;
int i /* = 0 */;
int c;
int ent;
int disp;
int hsize_reg;
final int hsize_reg;
int hshift;
// Set up the globals: g_init_bits - initial number of bits
@@ -222,7 +222,7 @@ class LZWEncoder {
}
//----------------------------------------------------------------------------
void encode(OutputStream os) throws IOException {
void encode(final OutputStream os) throws IOException {
os.write(initCodeSize); // write "initial code size" byte
remaining = imgW * imgH; // reset navigation variables
@@ -234,7 +234,7 @@ class LZWEncoder {
}
// Flush the packet to disk, and reset the accumulator
void flush_char(OutputStream outs) throws IOException {
void flush_char(final OutputStream outs) throws IOException {
if (a_count > 0) {
outs.write(a_count);
outs.write(accum, 0, a_count);
@@ -242,7 +242,7 @@ class LZWEncoder {
}
}
final int MAXCODE(int n_bits) {
final int MAXCODE(final int n_bits) {
return (1 << n_bits) - 1;
}
@@ -255,12 +255,12 @@ class LZWEncoder {
--remaining;
byte pix = pixAry[curPixel++];
final byte pix = pixAry[curPixel++];
return pix & 0xff;
}
void output(int code, OutputStream outs) throws IOException {
void output(final int code, final OutputStream outs) throws IOException {
cur_accum &= masks[cur_bits];
if (cur_bits > 0)

View File

@@ -89,7 +89,7 @@ public class NeuQuant {
/* Initialise network in range (0,0,0) to (255,255,255) and set parameters
----------------------------------------------------------------------- */
public NeuQuant(byte[] thepic, int len, int sample) {
public NeuQuant(final byte[] thepic, final int len, final int sample) {
int i;
int[] p;
@@ -109,13 +109,13 @@ public class NeuQuant {
}
public byte[] colorMap() {
byte[] map = new byte[3 * NETSIZE];
int[] index = new int[NETSIZE];
final byte[] map = new byte[3 * NETSIZE];
final int[] index = new int[NETSIZE];
for (int i = 0; i < NETSIZE; i++)
index[network[i][3]] = i;
int k = 0;
for (int i = 0; i < NETSIZE; i++) {
int j = index[i];
final int j = index[i];
map[k++] = (byte) (network[j][0]);
map[k++] = (byte) (network[j][1]);
map[k++] = (byte) (network[j][2]);
@@ -181,9 +181,15 @@ public class NeuQuant {
public void learn() {
int i, j, b, g, r;
int radius, rad, alpha, step, delta, samplepixels;
byte[] p;
int pix, lim;
int radius;
int rad;
int alpha;
int step;
int delta;
final int samplepixels;
final byte[] p;
int pix;
final int lim;
if (lengthcount < MINPICTUREBYTES)
samplefac = 1;
@@ -252,7 +258,7 @@ public class NeuQuant {
/* Search for BGR values 0..255 (after net is unbiased) and return colour index
---------------------------------------------------------------------------- */
public int map(int b, int g, int r) {
public int map(final int b, final int g, final int r) {
int i, j, dist, a, bestd;
int[] p;
@@ -338,7 +344,7 @@ public class NeuQuant {
/* Move adjacent neurons by precomputed alpha*(1-((i-j)^2/[r]^2)) in radpower[|i-j|]
--------------------------------------------------------------------------------- */
protected void alterneigh(int rad, int i, int b, int g, int r) {
protected void alterneigh(final int rad, final int i, final int b, final int g, final int r) {
int j, k, lo, hi, a, m;
int[] p;
@@ -361,7 +367,7 @@ public class NeuQuant {
p[0] -= (a * (p[0] - b)) / ALPHARADBIAS;
p[1] -= (a * (p[1] - g)) / ALPHARADBIAS;
p[2] -= (a * (p[2] - r)) / ALPHARADBIAS;
} catch (Exception ignored) {
} catch (final Exception ignored) {
} // prevents 1.3 miscompilation
}
if (k > lo) {
@@ -370,7 +376,7 @@ public class NeuQuant {
p[0] -= (a * (p[0] - b)) / ALPHARADBIAS;
p[1] -= (a * (p[1] - g)) / ALPHARADBIAS;
p[2] -= (a * (p[2] - r)) / ALPHARADBIAS;
} catch (Exception ignored) {
} catch (final Exception ignored) {
}
}
}
@@ -378,10 +384,10 @@ public class NeuQuant {
/* Move neuron i towards biased (b,g,r) by factor alpha
---------------------------------------------------- */
protected void altersingle(int alpha, int i, int b, int g, int r) {
protected void altersingle(final int alpha, final int i, final int b, final int g, final int r) {
/* alter hit neuron */
int[] n = network[i];
final int[] n = network[i];
n[0] -= (alpha * (n[0] - b)) / INITALPHA;
n[1] -= (alpha * (n[1] - g)) / INITALPHA;
n[2] -= (alpha * (n[2] - r)) / INITALPHA;
@@ -389,7 +395,7 @@ public class NeuQuant {
/* Search for biased BGR values
---------------------------- */
protected int contest(int b, int g, int r) {
protected int contest(final int b, final int g, final int r) {
/* finds closest neuron (min dist) and updates freq */
/* finds best neuron (min dist-bias) and returns position */

View File

@@ -12,14 +12,14 @@ public class ClipboardMonitorTest {
public void monitorTest() {
// 第一个监听
ClipboardUtil.listen((clipboard, contents) -> {
Object object = ClipboardUtil.getStr(contents);
final Object object = ClipboardUtil.getStr(contents);
Console.log("1# {}", object);
return contents;
}, false);
// 第二个监听
ClipboardUtil.listen((clipboard, contents) -> {
Object object = ClipboardUtil.getStr(contents);
final Object object = ClipboardUtil.getStr(contents);
Console.log("2# {}", object);
return contents;
});

View File

@@ -7,7 +7,7 @@ import cn.hutool.core.swing.clipboard.ClipboardUtil;
/**
* 剪贴板工具类单元测试
*
*
* @author looly
*
*/
@@ -18,9 +18,9 @@ public class ClipboardUtilTest {
try {
ClipboardUtil.setStr("test");
String test = ClipboardUtil.getStr();
final String test = ClipboardUtil.getStr();
Assert.assertEquals("test", test);
} catch (java.awt.HeadlessException e) {
} catch (final java.awt.HeadlessException e) {
// 忽略 No X11 DISPLAY variable was set, but this program performed an operation which requires it.
// ignore
}

View File

@@ -18,7 +18,7 @@ public class CaptchaTest {
@Test
public void lineCaptchaTest1() {
// 定义图形验证码的长和宽
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
final LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
Assert.assertNotNull(lineCaptcha.getCode());
Assert.assertTrue(lineCaptcha.verify(lineCaptcha.getCode()));
}
@@ -27,7 +27,7 @@ public class CaptchaTest {
@Ignore
public void lineCaptchaTest3() {
// 定义图形验证码的长和宽
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 70, 4, 15);
final LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 70, 4, 15);
lineCaptcha.setBackground(Color.yellow);
lineCaptcha.write("f:/test/captcha/tellow.png");
}
@@ -36,7 +36,7 @@ public class CaptchaTest {
@Ignore
public void lineCaptchaWithMathTest() {
// 定义图形验证码的长和宽
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 80);
final LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 80);
lineCaptcha.setGenerator(new MathGenerator());
lineCaptcha.setTextAlpha(0.8f);
lineCaptcha.write("f:/captcha/math.png");
@@ -47,7 +47,7 @@ public class CaptchaTest {
public void lineCaptchaTest2() {
// 定义图形验证码的长和宽
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
final LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
// LineCaptcha lineCaptcha = new LineCaptcha(200, 100, 4, 150);
// 图形验证码写出,可以写出到文件,也可以写出到流
lineCaptcha.write("f:/captcha/line.png");
@@ -67,7 +67,7 @@ public class CaptchaTest {
public void circleCaptchaTest() {
// 定义图形验证码的长和宽
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 20);
final CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 20);
// CircleCaptcha captcha = new CircleCaptcha(200, 100, 4, 20);
// 图形验证码写出,可以写出到文件,也可以写出到流
captcha.write("f:/captcha/circle.png");
@@ -80,7 +80,7 @@ public class CaptchaTest {
public void shearCaptchaTest() {
// 定义图形验证码的长和宽
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(203, 100, 4, 4);
final ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(203, 100, 4, 4);
// ShearCaptcha captcha = new ShearCaptcha(200, 100, 4, 4);
// 图形验证码写出,可以写出到文件,也可以写出到流
captcha.write("f:/captcha/shear.png");
@@ -93,7 +93,7 @@ public class CaptchaTest {
public void shearCaptchaTest2() {
// 定义图形验证码的长和宽
ShearCaptcha captcha = new ShearCaptcha(200, 100, 4, 4);
final ShearCaptcha captcha = new ShearCaptcha(200, 100, 4, 4);
// 图形验证码写出,可以写出到文件,也可以写出到流
captcha.write("d:/test/shear.png");
// 验证图形验证码的有效性返回boolean值
@@ -104,7 +104,7 @@ public class CaptchaTest {
@Ignore
public void ShearCaptchaWithMathTest() {
// 定义图形验证码的长和宽
ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 45, 4, 4);
final ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 45, 4, 4);
captcha.setGenerator(new MathGenerator());
// ShearCaptcha captcha = new ShearCaptcha(200, 100, 4, 4);
// 图形验证码写出,可以写出到文件,也可以写出到流
@@ -116,7 +116,7 @@ public class CaptchaTest {
@Test
@Ignore
public void GifCaptchaTest() {
GifCaptcha captcha = CaptchaUtil.createGifCaptcha(200, 100, 4);
final GifCaptcha captcha = CaptchaUtil.createGifCaptcha(200, 100, 4);
captcha.write("d:/test/gif_captcha.gif");
assert captcha.verify(captcha.getCode());
}
@@ -124,7 +124,7 @@ public class CaptchaTest {
@Test
@Ignore
public void bgTest(){
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(200, 100, 4, 1);
final LineCaptcha captcha = CaptchaUtil.createLineCaptcha(200, 100, 4, 1);
captcha.setBackground(Color.WHITE);
captcha.write("d:/test/test.jpg");
}

View File

@@ -89,11 +89,11 @@ public class ImgTest {
@Test
@Ignore
public void scaleTest() {
String downloadFile = "d:/test/1435859438434136064.JPG";
File file = FileUtil.file(downloadFile);
File fileScale = FileUtil.file(downloadFile + ".scale." + FileTypeUtil.getType(file));
final String downloadFile = "d:/test/1435859438434136064.JPG";
final File file = FileUtil.file(downloadFile);
final File fileScale = FileUtil.file(downloadFile + ".scale." + FileTypeUtil.getType(file));
Image img = ImgUtil.getImage(URLUtil.getURL(file));
final Image img = ImgUtil.getImage(URLUtil.getURL(file));
ImgUtil.scale(img, fileScale, 0.8f);
}
}

View File

@@ -54,7 +54,7 @@ public class ImgUtilTest {
@Test
@Ignore
public void rotateTest() throws IOException {
Image image = ImgUtil.rotate(ImageIO.read(FileUtil.file("e:/pic/366466.jpg")), 180);
final Image image = ImgUtil.rotate(ImageIO.read(FileUtil.file("e:/pic/366466.jpg")), 180);
ImgUtil.write(image, FileUtil.file("e:/pic/result.png"));
}
@@ -115,7 +115,7 @@ public class ImgUtilTest {
@Test
@Ignore
public void copyTest() {
BufferedImage image = ImgUtil.copyImage(ImgUtil.read("f:/pic/test.png"), BufferedImage.TYPE_INT_RGB);
final BufferedImage image = ImgUtil.copyImage(ImgUtil.read("f:/pic/test.png"), BufferedImage.TYPE_INT_RGB);
ImgUtil.write(image, FileUtil.file("f:/pic/test_dest.jpg"));
}
@@ -142,8 +142,8 @@ public class ImgUtilTest {
@Test
public void getMainColor() throws MalformedURLException {
BufferedImage read = ImgUtil.read(new URL("https://pic2.zhimg.com/v2-94f5552f2b142ff575306850c5bab65d_b.png"));
String mainColor = ImgUtil.getMainColor(read, new int[]{64,84,116});
final BufferedImage read = ImgUtil.read(new URL("https://pic2.zhimg.com/v2-94f5552f2b142ff575306850c5bab65d_b.png"));
final String mainColor = ImgUtil.getMainColor(read, new int[]{64,84,116});
System.out.println(mainColor);
}