mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
计算色差值,参数为null时返回最大色差值
This commit is contained in:
parent
a6f0193e19
commit
fe6ab048e3
@ -207,6 +207,10 @@ public class ColorUtil {
|
||||
* @since 6.0.0-M16
|
||||
*/
|
||||
public static int maxDistance(final Color color) {
|
||||
if (null == color) {
|
||||
// (0,0,0)到(256,256,256)的距离约等于442.336
|
||||
return 443;
|
||||
}
|
||||
final int maxX = RGB_COLOR_BOUND - 2 * color.getRed();
|
||||
final int maxY = RGB_COLOR_BOUND - 2 * color.getGreen();
|
||||
final int maxZ = RGB_COLOR_BOUND - 2 * color.getBlue();
|
||||
@ -223,7 +227,8 @@ public class ColorUtil {
|
||||
*/
|
||||
public static int computeColorDistance(Color color1, Color color2) {
|
||||
if (null == color1 || null == color2) {
|
||||
return 0;
|
||||
// (0,0,0)到(256,256,256)的距离约等于442.336
|
||||
return 443;
|
||||
}
|
||||
return (int) Math.sqrt(Math.pow(color1.getRed() - color2.getRed(), 2)
|
||||
+ Math.pow(color1.getGreen() - color2.getGreen(), 2)
|
||||
|
Loading…
Reference in New Issue
Block a user