diff --git a/CHANGELOG.md b/CHANGELOG.md index becec1f42..51547fef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,12 @@ ------------------------------------------------------------------------------------------------------------- -# 5.6.7 (2021-06-02) +# 5.6.7 (2021-06-03) ### 🐣新特性 * 【core 】 CharSequenceUtil增加join重载(issue#I3TFJ5@Gitee) * 【http 】 HttpRequest增加form方法重载(pr#337@Gitee) +* 【http 】 ImgUtil增加getMainColor方法(pr#338@Gitee) ### 🐞Bug修复 * 【core 】 修复FileUtil.normalize去掉末尾空格问题(issue#1603@Github) diff --git a/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java b/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java index c98afc437..d7938c95e 100644 --- a/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java @@ -43,7 +43,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; /** * 图片处理工具类:
@@ -1722,7 +1726,7 @@ public class ImgUtil { } if (null == result) { - throw new IllegalArgumentException("Image type of [" + imageUrl.toString() + "] is not supported!"); + throw new IllegalArgumentException("Image type of [" + imageUrl + "] is not supported!"); } return result; @@ -2006,6 +2010,7 @@ public class ImgUtil { * @param image {@link BufferedImage} * @param rgbFilters 过滤多种颜色 * @return {@link String} #ffffff + * @since 5.6.7 */ public static String getMainColor(BufferedImage image, int[]... rgbFilters) { int r, g, b; @@ -2040,10 +2045,10 @@ public class ImgUtil { maxCount = count; } } - String[] splitRgbStr = maxColor.split("-"); - String rHex = Integer.toHexString(Integer.valueOf(splitRgbStr[0])); - String gHex = Integer.toHexString(Integer.valueOf(splitRgbStr[1])); - String bHex = Integer.toHexString(Integer.valueOf(splitRgbStr[2])); + final String[] splitRgbStr = StrUtil.splitToArray(maxColor, '-'); + String rHex = Integer.toHexString(Integer.parseInt(splitRgbStr[0])); + String gHex = Integer.toHexString(Integer.parseInt(splitRgbStr[1])); + String bHex = Integer.toHexString(Integer.parseInt(splitRgbStr[2])); rHex = rHex.length() == 1 ? "0" + rHex : rHex; gHex = gHex.length() == 1 ? "0" + gHex : gHex; bHex = bHex.length() == 1 ? "0" + bHex : bHex;