I have a Collection of Integers
of Processing colors (it contains colors of images rescaled to 1x1 to get the "average" color).
I have this thing that must retrieve me the nearest color of the array :
public static int getNearestColor(Collection<Integer> colors, int color) {
return colors.stream()
.min(Comparator.comparingInt(i -> Math.abs(i - color)))
.orElseThrow(() -> new NoSuchElementException("No value present"));
}
But when I do this, it returns me a color that is way far than the input, but the array contains some colors that are nearest than the input, this is my problem that I don't understand ?