List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:com.teambrmodding.neotech.client.models.ModelItemFluidStorage.java
/** * Change standard color into color MC wants for vertex data * @param input The input/*from ww w . j ava2 s . c o m*/ * @return The correct color to add to the vertex data */ public static int fixColorForMC(int input) { // ABGR, MC is reverse for some reason Color outputColor = new Color(input); int a = outputColor.getAlpha(); int r = outputColor.getRed(); int g = outputColor.getGreen(); int b = outputColor.getBlue(); return new Color(b, g, r, a).getRGB(); }
From source file:ColorUtil.java
public static Color blend(Color c1, Color c2, double v) { double v2 = 1 - v; return c1 == null ? (c2 == null ? null : c2) : c2 == null ? c1/*w ww . j av a 2 s. c om*/ : new Color(Math.min(255, (int) (c1.getRed() * v2 + c2.getRed() * v)), Math.min(255, (int) (c1.getGreen() * v2 + c2.getGreen() * v)), Math.min(255, (int) (c1.getBlue() * v2 + c2.getBlue() * v)), Math.min(255, (int) (c1.getAlpha() * v2 + c2.getAlpha() * v))); }
From source file:Main.java
/** * Write a {@link Color} value into XML output. * * @param value/*from w w w.ja va 2s . co m*/ * value to write * * @return * XML string * * @throws IllegalArgumentException * if a validation error occured */ public static String printColor(Color value) { if (value == null) { throw new IllegalArgumentException("The provided color is invalid!"); } String r = Integer.toHexString(value.getRed()).trim(); if (r.length() == 1) r = "0" + r; String g = Integer.toHexString(value.getGreen()).trim(); if (g.length() == 1) g = "0" + g; String b = Integer.toHexString(value.getBlue()).trim(); if (b.length() == 1) b = "0" + b; return "#" + r + g + b; }
From source file:ImageProcessing.ImageProcessing.java
public static void processGrayscale(BufferedImage image) { //Converts a color image to a Grayscale image. for (int i = 0; i < image.getHeight(); i++) { for (int j = 0; j < image.getWidth(); j++) { int rgb = image.getRGB(j, i); Color currentPixel = new Color(rgb, true); //Find the average from all the color components for the given pixel. int grayLevel = (currentPixel.getRed() + currentPixel.getGreen() + currentPixel.getBlue()) / 3; int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel; image.setRGB(j, i, gray);/* ww w .j ava 2 s. c o m*/ } } }
From source file:com.igormaznitsa.sciareto.ui.UiUtils.java
public static int calculateBrightness(@Nonnull final Color color) { return (int) Math.sqrt(color.getRed() * color.getRed() * .241d + color.getGreen() * color.getGreen() * .691d + color.getBlue() * color.getBlue() * .068d); }
From source file:se.trixon.almond.GraphicsHelper.java
public static String colorToAABBGGRR(Color color, String... prefixSuffix) { String rr = StringUtils.leftPad(Integer.toHexString(color.getRed()), 2, "0"); String gg = StringUtils.leftPad(Integer.toHexString(color.getGreen()), 2, "0"); String bb = StringUtils.leftPad(Integer.toHexString(color.getBlue()), 2, "0"); String aa = StringUtils.leftPad(Integer.toHexString(color.getAlpha()), 2, "0"); StringBuilder builder = new StringBuilder(); if (prefixSuffix.length > 0) { builder.append(prefixSuffix[0]); }/* w ww. j a v a2s . c o m*/ builder.append(aa).append(bb).append(gg).append(rr); if (prefixSuffix.length > 1) { builder.append(prefixSuffix[1]); } return builder.toString(); }
From source file:net.cloudkit.relaxation.CaptchaTest.java
public static void clearNoise(BufferedImage image) { final int width = image.getWidth(); final int height = image.getHeight(); /*/*w w w. j av a 2s . c o m*/ for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { image.setRGB(x, y, Color.WHITE.getRGB()); } } */ for (int x = image.getMinX(); x < width; x++) { for (int y = image.getMinY(); y < height; y++) { int point = image.getRGB(x, y); // int top = (y > 0) ? image.getRGB(x, y - 1) : -1; // ? int right = (x < width - 1) ? image.getRGB(x + 1, y) : -1; // int bottom = (y < height - 1) ? image.getRGB(x, y + 1) : -1; // int left = (x > 0) ? image.getRGB(x - 1, y) : -1; // ? int topRight = ((x < width - 1) && (y > 0)) ? image.getRGB(x + 1, y - 1) : -1; // int topLeft = ((x > 0) && (y > 0)) ? image.getRGB(x - 1, y - 1) : -1; // ? int bottomRight = ((x < width - 1) && (y < height - 1)) ? image.getRGB(x + 1, y + 1) : -1; // int bottomLeft = ((x > 0) && (y < height - 1)) ? image.getRGB(x - 1, y + 1) : -1; int i = 0; i = (top != -1) ? i + 1 : i; i = (right != -1) ? i + 1 : i; i = (bottom != -1) ? i + 1 : i; i = (left != -1) ? i + 1 : i; i = (topRight != -1) ? i + 1 : i; i = (topLeft != -1) ? i + 1 : i; i = (bottomRight != -1) ? i + 1 : i; i = (bottomLeft != -1) ? i + 1 : i; // System.out.println("i:" + i + ", top:" + top + ", right:" + right + ", bottom:" + bottom + ", left:" + left + ", topRight:" + topRight + ", topLeft:" + topLeft + ", bottomRight:" + bottomRight + ", bottomLeft:" + bottomLeft); if (i < 5) { image.setRGB(x, y, Color.WHITE.getRGB()); } /* int leftNearby = 0; if(left != -1) { int secondLeft = (x > 1) ? image.getRGB(x - 2, y) : -1; int threeLeft = (x > 2) ? image.getRGB(x - 3, y) : -1; leftNearby = ((left == -1) ? 0 : 1) + ((secondLeft == -1) ? 0 : 1) + ((threeLeft == -1) ? 0 : 1); } int rightNearby = 0; if(right != -1) { int secondRight = (x + 1 < width - 1) ? image.getRGB(x + 2, y) : -1; int threeRight = (x + 2 < width - 1) ? image.getRGB(x + 3, y) : -1; rightNearby = ((right == -1) ? 0 : 1) + ((secondRight == -1) ? 0 : 1) + ((threeRight == -1) ? 0 : 1); } int topNearby = 0; if(top != -1) { int secondTop = (y > 1) ? image.getRGB(x, y - 2) : -1; int threeTop = (y > 2) ? image.getRGB(x, y - 3) : -1; topNearby = ((top == -1) ? 0 : 1) + ((secondTop == -1) ? 0 : 1) + ((threeTop == -1) ? 0 : 1); } int bottomNearby = 0; if(bottom != -1) { int secondBottom = (y + 1 < height - 1) ? image.getRGB(x, y + 2) : -1; int threeBottom = (y + 2 < height - 1) ? image.getRGB(x, y + 3) : -1; bottomNearby = ((bottom == -1) ? 0 : 1) + ((secondBottom == -1) ? 0 : 1) + ((threeBottom == -1) ? 0 : 0); } System.out.println(leftNearby + " " + rightNearby + " " + topNearby + " " + bottomNearby); if (leftNearby != 2 && rightNearby != 2 && topNearby != 2 && bottomNearby != 2) { image.setRGB(x, y, Color.WHITE.getRGB()); } */ /* System.out.println(point - top); System.out.println(point - right); System.out.println(point - bottom); System.out.println(point - left); System.out.println(point - topRight); System.out.println(point - topLeft); System.out.println(point - bottomRight); System.out.println(point - bottomLeft); */ // if (point != top && point != right && point != bottom && point != left && point != topRight && point != topLeft && point != bottomRight && point != bottomLeft) { // image.setRGB(x, y, Color.WHITE.getRGB()); // } /* Color color = new Color(image.getRGB(x, y)); if((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { // image.setRGB(x, y, Color.WHITE.getRGB()); } else if((color.getRed() + color.getGreen() + color.getBlue()) < 400) { image.setRGB(x, y, Color.BLACK.getRGB()); } */ Color color = new Color(image.getRGB(x, y)); if ((color.getRed() + color.getGreen() + color.getBlue()) < 600) { image.setRGB(x, y, Color.BLACK.getRGB()); } else { image.setRGB(x, y, Color.WHITE.getRGB()); } } } }
From source file:se.ngm.ditaaeps.EpsRenderer.java
public static boolean isColorDark(Color color) { int brightness = Math.max(color.getRed(), color.getGreen()); brightness = Math.max(color.getBlue(), brightness); if (brightness < 200) { if (DEBUG) System.out.println("Color " + color + " is dark"); return true; }/*from ww w .j a va 2 s. c o m*/ if (DEBUG) System.out.println("Color " + color + " is not dark"); return false; }
From source file:com.glaf.core.util.Tools.java
public static String javaColorToCSSColor(Color paramColor) { StringBuffer localStringBuffer = new StringBuffer(30); localStringBuffer.append("rgb("); localStringBuffer.append(paramColor.getRed()); localStringBuffer.append(','); localStringBuffer.append(paramColor.getGreen()); localStringBuffer.append(','); localStringBuffer.append(paramColor.getBlue()); localStringBuffer.append(')'); return localStringBuffer.toString(); }
From source file:org.opensha.commons.util.XMLUtils.java
/** * Convenience method for writing a java 'Color' object to XML with the given * element name/*from w w w. j ava 2 s. c o m*/ * * @param parent * @param color * @param elName */ public static void colorToXML(Element parent, Color color, String elName) { Element el = parent.addElement(elName); el.addAttribute("r", color.getRed() + ""); el.addAttribute("g", color.getGreen() + ""); el.addAttribute("b", color.getBlue() + ""); el.addAttribute("a", color.getAlpha() + ""); }