List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:org.onexus.website.api.widgets.tableviewer.decorators.scale.ColorDecorator.java
public static double lum(Color color) { int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); return .299 * r + .587 * g + .114 * b; }
From source file:com.github.fritaly.graphml4j.Utils.java
/** * Encodes the given color into an hexadecimal string like "#RRGGBBAA" or * "#RRGGBB" (whether the transparency is set to 0). * * @param color//w w w . j a v a 2 s . co m * a color to encode. Can't be null. * @return a string representing the encoded color. */ static String encode(Color color) { Validate.notNull(color, "The given color is null"); if (color.getAlpha() == 255) { return String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue()); } else { return String.format("#%02X%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); } }
From source file:edu.scripps.fl.curves.plot.CurvePlotDrawingSupplier.java
private static Color toGreyScale(Color c) { int rgb = (int) (((double) c.getRed() * 0.299) + ((double) c.getGreen() * 0.587) + ((double) c.getBlue() * 0.114)); if (rgb > 255) rgb = 255;//w ww. j a va2 s. c o m return new Color(rgb, rgb, rgb); }
From source file:PaintUtils.java
/** Paints 3 different strokes around a shape to indicate focus. * The widest stroke is the most transparent, so this achieves a nice * "glow" effect./* w w w . j a va 2 s . c o m*/ * <P>The catch is that you have to render this underneath the shape, * and the shape should be filled completely. * * @param g the graphics to paint to * @param shape the shape to outline * @param biggestStroke the widest stroke to use. */ public static void paintFocus(Graphics2D g, Shape shape, int biggestStroke) { Color focusColor = getFocusRingColor(); Color[] focusArray = new Color[] { new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 255), new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 170), new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 110) }; g.setStroke(new BasicStroke(biggestStroke)); g.setColor(focusArray[2]); g.draw(shape); g.setStroke(new BasicStroke(biggestStroke - 1)); g.setColor(focusArray[1]); g.draw(shape); g.setStroke(new BasicStroke(biggestStroke - 2)); g.setColor(focusArray[0]); g.draw(shape); g.setStroke(new BasicStroke(1)); }
From source file:chiliad.parser.pdf.model.MToken.java
public static String colorToRgba(Color c) { return "rgba(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + "," + c.getAlpha() / 255 + ")"; }
From source file:org.polymap.rhei.batik.engine.svg.Svg2PngTask.java
static RGB getTypedRGB(String rgbStr) { if (rgbStr == null) { return null; }//from www .ja va 2 s . c o m if (rgbStr.startsWith("#")) { rgbStr = rgbStr.substring(1); } if (!rgbStr.startsWith("0x")) { rgbStr = "0x" + rgbStr; } Color color = Color.decode(rgbStr); return new RGB(color.getRed(), color.getGreen(), color.getBlue()); }
From source file:Main.java
public static byte[] getCompressedImage(byte[] rgb) { BufferedImage image;//w ww. ja v a2s. 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:Main.java
public static Color adjust2(Color original, double value, int maximumrange) { if (value > 1) value = 1;//from ww w . j a va 2 s . c o m if (value < 0) value = 0; int r = original.getRed(); int g = original.getGreen(); int b = original.getBlue(); double nah = value * maximumrange; r += (int) nah; g += (int) nah; b += (int) nah; r = colorSnap(r); g = colorSnap(g); b = colorSnap(b); return new Color(r, g, b, original.getAlpha()); }
From source file:JavaTron.JTP.java
/** * Parses a Color type to a CSV type RGB string * @param c A Color Object//w w w. j a va2 s. c o m * @return A String in the form of R,G,B i.e '0,255,127' */ public static String parseColor(Color c) { int red = c.getRed(); int green = c.getGreen(); int blue = c.getBlue(); String csv = Integer.toString(red) + "," + Integer.toString(green) + "," + Integer.toString(blue); return csv; }
From source file:Main.java
/** * Linear interpolation./* www. j av a2s . 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); }