@Override public void setIconPixel(final int x, final int y, final ColorRGB color) { final Color awtColor = new Color(color.getRed(), color.getGreen(), color.getBlue()); // TODO this would be nice but doesn't work // button.getGraphics().setColor(awtColor); // button.getGraphics().drawLine(x, y, x, y); // But using an old reference does work graphics.setColor(awtColor); graphics.drawLine(x, y, x, y); }
/** * Constructs a ChannelCollection containing the three RGB values of a given * color. */ public ChannelCollection(ColorRGB color) { this( Arrays.asList( new Double[]{ (double) color.getRed(), (double) color.getGreen(), (double) color.getBlue()})); }
/** * Get the AWT {@link Color} corresponding to the given ImageJ * {@link ColorRGB} plus explicit alpha component (0-255). * * @param c RGB color * @param alpha alpha value (0-255) * @return AWT color */ public static Color getColor(final ColorRGB c, final int alpha) { if (c == null) return null; if (alpha < 0 || alpha > 255) { throw new IllegalArgumentException("Alpha value of " + alpha + " is out of range (0-255)"); } return new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha); }
private Color getDefaultStrokeColor(final OverlaySettings settings) { final ColorRGB color = settings.getLineColor(); final int r = color.getRed(); final int g = color.getGreen(); final int b = color.getBlue(); return new Color(r, g, b, 255); }
/** * Gets the AWT {@link Color} corresponding to the given ImageJ * {@link ColorRGB}. */ public static Color getColor(final ColorRGB c) { if (c == null) return null; return new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()); }
/** * Gets the color as a packed integer, 8 bits per color component. HSB is * alpha, next is red, then green, and finally blue is LSB. */ public int getARGB() { final int a = getAlpha(); final int r = getRed(); final int g = getGreen(); final int b = getBlue(); return (a << 24) | (r << 16) | (g << 8) | b; }
@Override public void save() { Prefs.put(getClass(), LAST_FG_RED, lastFgColor.getRed()); Prefs.put(getClass(), LAST_FG_GREEN, lastFgColor.getGreen()); Prefs.put(getClass(), LAST_FG_BLUE, lastFgColor.getBlue()); Prefs.put(getClass(), LAST_BG_RED, lastBgColor.getRed()); Prefs.put(getClass(), LAST_BG_GREEN, lastBgColor.getGreen()); Prefs.put(getClass(), LAST_BG_BLUE, lastBgColor.getBlue()); cleanStrings(); super.save(); }
private Color getDefaultFillColor(final OverlaySettings settings) { final ColorRGB color = settings.getFillColor(); final int r = color.getRed(); final int g = color.getGreen(); final int b = color.getBlue(); final int a = settings.getAlpha(); return new Color(r, g, b, a); }
/** * Gets the color as a packed integer, 8 bits per color component. HSB is * alpha, next is red, then green, and finally blue is LSB. */ public int getARGB() { final int a = getAlpha(); final int r = getRed(); final int g = getGreen(); final int b = getBlue(); return (a << 24) | (r << 16) | (g << 8) | b; }
/** * Convert this ColorRGB to a string in the format specified by <a * href="http://www.w3.org/TR/css3-color/">CSS Color Module Level 3 - W3C * Recommendation 07 June 2011</a>. * <p> * We preferentially encode using one of the colors in the table and fall back * to the hex encoding. * </p> * * @return HTML-encoded string */ public String toHTMLColor() { // return name of matching preset, if possible final String preset = Colors.getName(this); if (preset != null) return preset; // return hex-encoded string final int r = getRed(); final int g = getGreen(); final int b = getBlue(); return String.format("#%02x%02x%02x", r, g, b); }
/** * Convert this ColorRGB to a string in the format specified by <a * href="http://www.w3.org/TR/css3-color/">CSS Color Module Level 3 - W3C * Recommendation 07 June 2011</a>. * <p> * We preferentially encode using one of the colors in the table and fall back * to the hex encoding. * </p> * * @return HTML-encoded string */ public String toHTMLColor() { // return name of matching preset, if possible final String preset = Colors.getName(this); if (preset != null) return preset; // return hex-encoded string final int r = getRed(); final int g = getGreen(); final int b = getBlue(); return String.format("#%02x%02x%02x", r, g, b); }
private static ColorTable8 spectrum() { final byte[] r = new byte[256], g = new byte[256], b = new byte[256]; for (int i = 0; i < 256; i++) { final ColorRGB c = ColorRGB.fromHSVColor(i / 255d, 1d, 1d); r[i] = (byte) c.getRed(); g[i] = (byte) c.getGreen(); b[i] = (byte) c.getBlue(); } return new ColorTable8(r, g, b); }
new IndexColorModel(1, 2, new byte[] { 0, (byte) color.getRed() }, new byte[] { 0, (byte) color.getGreen() }, new byte[] { 0, (byte) color.getBlue() }, new byte[] { 0, (byte) overlay.getData().getAlpha() }); final int w = (int) (maxX - minX);
@Test public void testColorRGBIntIntInt() { assertEquals(1, new ColorRGB(1, 2, 3).getRed()); assertEquals(2, new ColorRGB(1, 2, 3).getGreen()); assertEquals(3, new ColorRGB(1, 2, 3).getBlue()); }
@Test public void testColorRGBString() { assertEquals(1, new ColorRGB("1,2,3").getRed()); assertEquals(2, new ColorRGB("1,2,3").getGreen()); assertEquals(3, new ColorRGB("1,2,3").getBlue()); }