List of usage examples for java.awt Color getRed
public int getRed()
From source file:Main.java
public static String getColorString(Color color) { StringBuffer buffer = new StringBuffer("#"); //$NON-NLS-1$ appendComponent(buffer, color.getRed()); appendComponent(buffer, color.getGreen()); appendComponent(buffer, color.getBlue()); return buffer.toString(); }
From source file:Utils.java
/** * Derives a color by adding the specified offsets to the base color's * hue, saturation, and brightness values. The resulting hue, saturation, * and brightness values will be contrained to be between 0 and 1. * @param base the color to which the HSV offsets will be added * @param dH the offset for hue//from ww w . j a v a 2s . co m * @param dS the offset for saturation * @param dB the offset for brightness * @return Color with modified HSV values */ public static Color deriveColorHSB(Color base, float dH, float dS, float dB) { float hsb[] = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null); hsb[0] += dH; hsb[1] += dS; hsb[2] += dB; return Color.getHSBColor(hsb[0] < 0 ? 0 : (hsb[0] > 1 ? 1 : hsb[0]), hsb[1] < 0 ? 0 : (hsb[1] > 1 ? 1 : hsb[1]), hsb[2] < 0 ? 0 : (hsb[2] > 1 ? 1 : hsb[2])); }
From source file:Main.java
/** * Linear interpolation.//from w ww. j ava2s .c o m * @param color0 * @param color1 * @param amount * @return */ public static Color Lerp(Color color0, Color color1, double amount) { int r = (int) Lerp(color0.getRed(), color1.getRed(), amount); int g = (int) Lerp(color0.getGreen(), color1.getGreen(), amount); int b = (int) Lerp(color0.getBlue(), color1.getBlue(), amount); int a = (int) Lerp(color0.getAlpha(), color1.getAlpha(), amount); if (r > 255) r = 255; if (r < 0) r = 0; if (g > 255) g = 255; if (g < 0) g = 0; if (b > 255) b = 255; if (b < 0) b = 0; if (a > 255) a = 255; if (a < 0) a = 0; return new Color(r, g, b, a); }
From source file:Main.java
public static byte[] getCompressedImage(byte[] rgb) { BufferedImage image;/*from w w w . ja v a2 s . c o m*/ int width; int height; try { image = ImageIO.read(new ByteArrayInputStream(rgb)); width = image.getWidth(); height = image.getHeight(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(image.getRGB(j, i)); int red = (int) (c.getRed() * 0.299); int green = (int) (c.getGreen() * 0.587); int blue = (int) (c.getBlue() * 0.114); Color newColor = new Color(red + green + blue, red + green + blue, red + green + blue); image.setRGB(j, i, newColor.getRGB()); } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close(); return imageInByte; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:edu.ku.brc.ui.ColorWrapper.java
/** * Helper to convert a Color into a string "r,g,b" * @param c the color//from w w w. j a va 2s . c om * @return the comma separated string */ public static String toString(Color c) { return c.getRed() + ", " + c.getGreen() + ", " + c.getBlue(); }
From source file:proteinHypernetworkVisualization.implementation.jung.visualization.DefaultGraphStyle.java
public static Color makeTransparent(Color c) { return new Color(c.getRed(), c.getGreen(), c.getBlue(), 150); }
From source file:org.esa.beam.visat.toolviews.stat.MaskSelectionToolSupport.java
private static Color createAlphaColor(Color color, int alpha) { return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); }
From source file:Main.java
public static void addColorProperty(Document document, Element parent, String name, Color value) { addPropertyNode(document, parent, name).setAttribute(COLOR_ATTR, value.getRed() + "," + value.getGreen() + "," + value.getBlue()); }
From source file:com.embedler.moon.jtxt2img.CoreHelper.java
public static String rgb2hex(Color color) { Validate.notNull(color, "Color must not be null"); return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue()); }
From source file:Main.java
public static Color getGradientRgbColor(float ratio, Color minColor, Color maxColor) { if (ratio < 0) ratio = 0.0F;/* w ww.jav a 2 s . c o m*/ if (ratio > 1.0) ratio = 1.0F; int red = (int) (maxColor.getRed() * ratio + minColor.getRed() * (1.0 - ratio)); int green = (int) (maxColor.getGreen() * ratio + minColor.getGreen() * (1 - ratio)); int blue = (int) (maxColor.getBlue() * ratio + minColor.getBlue() * (1 - ratio)); Color gradient = new Color(red, green, blue); return gradient; }