Here you can find the source of contrast(@Nonnull Color color)
Parameter | Description |
---|---|
color | the source color |
public static Color contrast(@Nonnull Color color)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import javax.annotation.Nonnull; public class Main { /**/*from ww w . jav a 2 s.c o m*/ * Return the color (Black/White) that most contrasts with the specified * color. * * @param color the source color * @return the contrasting color */ public static Color contrast(@Nonnull Color color) { int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); int average = (red + green + blue) / 3; return (average >= 128) ? Color.BLACK : Color.WHITE; } }