List of usage examples for java.awt Color getAlpha
public int getAlpha()
From source file:Main.java
/** * Adjusts a preset color to a roughness value. * @param orig The original color/*from w ww . ja va 2s . c o m*/ * @param a The roughness value. * @param maxmin The maximum and minimum differential. * @return A color that has been adjust to match the original and roughness. */ public static Color adjust(Color orig, double a, int maxmin) { if (a > 1) a = 1; if (a < 0) a = 0; int r = orig.getRed(); int g = orig.getGreen(); int b = orig.getBlue(); r = (int) (r - (a * maxmin)); g = (int) (g - (a * maxmin)); b = (int) (b - (a * maxmin)); r = colorSnap(r); g = colorSnap(g); b = colorSnap(b); return new Color(r, g, b, orig.getAlpha()); }
From source file:Main.java
public static Color adjust2(Color original, double value, int maximumrange) { if (value > 1) value = 1;/* w w w . j a v a 2 s . c om*/ 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: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/*from w w w . ja v a2 s . com*/ : 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: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]); }//from ww w. ja va2 s . 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:org.opensha.commons.geo.RegionUtils.java
private static String colorToHex(Color c) { StringBuffer sb = new StringBuffer(); sb.append(toHex(c.getAlpha())); sb.append(toHex(c.getBlue()));//from w ww .j a va 2s . c om sb.append(toHex(c.getGreen())); sb.append(toHex(c.getRed())); return sb.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() + ""); }
From source file:org.apache.fop.render.rtf.TextAttributesConverter.java
private static void attrFontColor(Color colorType, RtfAttributes rtfAttr) { // Cell background color if (colorType != null) { if (colorType.getAlpha() != 0 || colorType.getRed() != 0 || colorType.getGreen() != 0 || colorType.getBlue() != 0) { rtfAttr.set(RtfText.ATTR_FONT_COLOR, convertFOPColorToRTF(colorType)); }/*from ww w .ja va 2 s . c o m*/ } }
From source file:imageprocessingproject.ImageHistogram.java
public static BufferedImage autoContrastImage(BufferedImage image) { createContrastLUT(image);/*from w ww . j a v a2 s . c om*/ int height = image.getHeight(); int width = image.getWidth(); int r, g, b; Color c; BufferedImage tempImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { c = new Color(image.getRGB(i, j)); r = (int) (255 * contrast_lut[c.getRed()]); g = (int) (255 * contrast_lut[c.getGreen()]); b = (int) (255 * contrast_lut[c.getBlue()]); tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB()); } } return tempImage; }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartRendererFactory.java
private static void configureXYDifferenceRenderer(FormattedXYDifferenceRenderer renderer, ValueSource valueSource, PlotConfiguration plotConfiguration) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); SeriesFormat seriesFormat = valueSource.getSeriesFormat(); DimensionConfig domainConfig = valueSource.getDomainConfig(); DimensionConfig colorDimensionConfig = plotConfiguration.getDimensionConfig(PlotDimension.COLOR); DimensionConfig shapeDimensionConfig = plotConfiguration.getDimensionConfig(PlotDimension.SHAPE); int seriesCount = 1;// valueSource.getSeriesDataForAllGroupCells().groupCellCount(); // Loop all series and set series format. // Format based on dimension configs will be set later on in initFormatDelegate(). for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) { // configure linestyle if (seriesFormat.getLineStyle() == LineStyle.NONE) { } else {/*from w w w. j a va 2 s . co m*/ renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false); } // configure series shape if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) { if (seriesFormat.getItemShape() != ItemShape.NONE) { renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape()); } else { } } // configure series color if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) { Color itemColor = seriesFormat.getItemColor(); Color halfTransparentPaint = DataStructureUtils.setColorAlpha(itemColor, itemColor.getAlpha() / 2); renderer.setSeriesPaint(0, halfTransparentPaint); renderer.setSeriesFillPaint(0, halfTransparentPaint); renderer.setPositivePaint(halfTransparentPaint); renderer.setNegativePaint(new Color(255 - itemColor.getRed(), 255 - itemColor.getGreen(), 255 - itemColor.getBlue(), itemColor.getAlpha() / 2)); } renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT); } }
From source file:org.jtrfp.trcl.core.Texture.java
private static VectorList colorVL(Color c) { final double[] color = new double[] { c.getRed() / 255., c.getGreen() / 255., c.getBlue() / 255., c.getAlpha() / 255. }; return new VectorList() { @Override/*from w w w .ja v a2 s . c om*/ public int getNumVectors() { return 1; } @Override public int getNumComponentsPerVector() { return 4; } @Override public double componentAt(int vectorIndex, int componentIndex) { return color[componentIndex]; } @Override public void setComponentAt(int vectorIndex, int componentIndex, double value) { throw new RuntimeException( "Static palette created by Texture(Color c, TR tr) cannot be written to."); } }; }