mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -299,7 +299,7 @@ public class BackgroundRemoval {
|
||||
}
|
||||
}
|
||||
|
||||
final Map<String, Integer> map = new HashMap<>(list.size());
|
||||
final Map<String, Integer> map = new HashMap<>(list.size(), 1);
|
||||
for (final String string : list) {
|
||||
Integer integer = map.get(string);
|
||||
if (integer == null) {
|
||||
@@ -309,7 +309,7 @@ public class BackgroundRemoval {
|
||||
}
|
||||
map.put(string, integer);
|
||||
}
|
||||
String max = "";
|
||||
String max = StrUtil.EMPTY;
|
||||
long num = 0;
|
||||
for (final Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
final String key = entry.getKey();
|
||||
@@ -326,7 +326,7 @@ public class BackgroundRemoval {
|
||||
return ImgUtil.toHex(Integer.parseInt(strings[0]), Integer.parseInt(strings[1]),
|
||||
Integer.parseInt(strings[2]));
|
||||
}
|
||||
return "";
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- private
|
||||
|
@@ -1356,6 +1356,19 @@ public class ImgUtil {
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文字创建透明背景的PNG图片
|
||||
*
|
||||
* @param str 文字
|
||||
* @param font 字体{@link Font}
|
||||
* @param fontColor 字体颜色,默认黑色
|
||||
* @param out 图片输出地
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static void createTransparentImage(String str, Font font, Color fontColor, ImageOutputStream out) throws IORuntimeException {
|
||||
writePng(createImage(str, font, null, fontColor, BufferedImage.TYPE_INT_ARGB), out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文字创建PNG图片
|
||||
*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.swing.img;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.swing.img.ImgUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -147,4 +147,26 @@ public class ImgUtilTest {
|
||||
System.out.println(mainColor);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void createImageTest() throws IORuntimeException, IOException {
|
||||
ImgUtil.createImage(
|
||||
"版权所有",
|
||||
new Font("黑体", Font.BOLD, 50),
|
||||
Color.WHITE,
|
||||
Color.BLACK,
|
||||
ImageIO.createImageOutputStream(new File("d:/test/createImageTest.png"))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void createTransparentImageTest() throws IORuntimeException, IOException {
|
||||
ImgUtil.createTransparentImage(
|
||||
"版权所有",
|
||||
new Font("黑体", Font.BOLD, 50),
|
||||
Color.BLACK,
|
||||
ImageIO.createImageOutputStream(new File("d:/test/createTransparentImageTest.png"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user