ColorHelper { public static Color getColorWithAlpha(Color c, double alpha) { int a = (int) (MAX_RGB_VALUE * alpha); if (a < 0) { a = 0; } else if (a > MAX_RGB_VALUE) { a = MAX_RGB_VALUE; } if (c != null){ return new Color(c.getRed(), c.getGreen(), c.getBlue(), a); }else{ return new Color(MAX_RGB_VALUE, MAX_RGB_VALUE, MAX_RGB_VALUE, a); } } private  ColorHelper(); static Color getColorWithAlpha(Color c, double alpha); static Color invert(Color c); static Color getColorFromHSL(double h, double s, double l); static BufferedImage getColorSpaceImage(); static float getHue(Color color); static float getLightness(Color color); static final int MAX_RGB_VALUE; }
@Test public void testGetColorWithAlpha() { System.out.println("getColorWithAlpha"); Color c = new Color(40, 40, 40); double alpha = 0.5; Color expResult = new Color(40, 40, 40, 127); Color result = ColorHelper.getColorWithAlpha(c, alpha); assertEquals(expResult, result); alpha = -1.0; result = ColorHelper.getColorWithAlpha(c, alpha); expResult = new Color(40, 40, 40, 0); alpha = 2.0; result = ColorHelper.getColorWithAlpha(c, alpha); expResult = new Color(40, 40, 40, 255); }