Java Code Examples for java.awt.Color#getRed()
The following examples show how to use
java.awt.Color#getRed() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: RRDiagram File: Utils.java License: Apache License 2.0 | 6 votes |
public static String convertColorToHtml(Color c) { StringBuilder connectorColorSB = new StringBuilder("#"); if (c.getRed() < 16) { connectorColorSB.append('0'); } connectorColorSB.append(Integer.toHexString(c.getRed())); if (c.getGreen() < 16) { connectorColorSB.append('0'); } connectorColorSB.append(Integer.toHexString(c.getGreen())); if (c.getBlue() < 16) { connectorColorSB.append('0'); } connectorColorSB.append(Integer.toHexString(c.getBlue())); String connectorColor = connectorColorSB.toString(); return connectorColor; }
Example 2
Source Project: MyBox File: ImageBinary.java License: Apache License 2.0 | 6 votes |
@Override protected Color operateColor(Color color) { int gray; if (grayed) { gray = color.getRed(); } else { gray = ImageColor.RGB2GrayValue(color); } Color newColor; if (gray < intPara1) { newColor = Color.BLACK; } else { newColor = Color.WHITE; } return newColor; }
Example 3
Source Project: jdk8u60 File: CheckAttributedTree.java License: GNU General Public License v2.0 | 6 votes |
/** Add a highlighted region based on the positions in an Info object. */ private void addHighlight(Highlighter h, Info info, Color c) { int start = info.start; int end = info.end; if (start == -1 && end == -1) return; if (start == -1) start = end; if (end == -1) end = start; try { h.addHighlight(info.start, info.end, new DefaultHighlighter.DefaultHighlightPainter(c)); if (info.pos != -1) { Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40% h.addHighlight(info.pos, info.pos + 1, new DefaultHighlighter.DefaultHighlightPainter(c2)); } } catch (BadLocationException e) { e.printStackTrace(); } }
Example 4
Source Project: pentaho-reporting File: PdfGraphics2D.java License: GNU Lesser General Public License v2.1 | 6 votes |
/** * Method contributed by Alexej Suchov * * @see Graphics2D#setPaint(Paint) */ @Override public void setPaint( final Paint paint ) { if ( paint == null ) { return; } this.paint = paint; realPaint = paint; if ( ( composite instanceof AlphaComposite ) && ( paint instanceof Color ) ) { final AlphaComposite co = (AlphaComposite) composite; if ( co.getRule() == 3 ) { final Color c = (Color) paint; this.paint = new Color( c.getRed(), c.getGreen(), c.getBlue(), (int) ( c.getAlpha() * alpha ) ); realPaint = paint; } } }
Example 5
Source Project: bamboobsc File: SimpleUtils.java License: Apache License 2.0 | 5 votes |
public static int[] getColorRGB2(String color) throws Exception { if (StringUtils.isEmpty(color) || color.length()!=7) { return new int[] {0, 0, 0}; } Color c = Color.decode(color); return new int[]{ c.getRed(), c.getGreen(), c.getBlue() }; }
Example 6
Source Project: swcv File: ImageOutline.java License: MIT License | 5 votes |
public static boolean isIncluded(Color target, Color pixel, int tolerance) { int rT = target.getRed(); int gT = target.getGreen(); int bT = target.getBlue(); int rP = pixel.getRed(); int gP = pixel.getGreen(); int bP = pixel.getBlue(); return ((rP - tolerance <= rT) && (rT <= rP + tolerance) && (gP - tolerance <= gT) && (gT <= gP + tolerance) && (bP - tolerance <= bT) && (bT <= bP + tolerance)); }
Example 7
Source Project: Pixelitor File: ValueNoise.java License: GNU General Public License v3.0 | 5 votes |
@Override public BufferedImage doTransform(BufferedImage src, BufferedImage dest) { int[] lookupTable = new int[256]; Color c1 = color1.getColor(); Color c2 = color2.getColor(); int[] colorArray1 = {c1.getAlpha(), c1.getRed(), c1.getGreen(), c1.getBlue()}; int[] colorArray2 = {c2.getAlpha(), c2.getRed(), c2.getGreen(), c2.getBlue()}; for (int i = 0, lookupTableLength = lookupTable.length; i < lookupTableLength; i++) { lookupTable[i] = ImageUtils.lerpAndPremultiply( i / 255.0f, colorArray1, colorArray2); } int[] destData = ImageUtils.getPixelsAsArray(dest); int width = dest.getWidth(); int height = dest.getHeight(); float frequency = 1.0f / scale.getValueAsFloat(); float persistence = 0.6f; float amplitude = 1.0f; var pt = new StatusBarProgressTracker(NAME, height); Future<?>[] futures = new Future[height]; for (int y = 0; y < height; y++) { int finalY = y; Runnable lineTask = () -> calculateLine(lookupTable, destData, width, frequency, persistence, amplitude, finalY); futures[y] = ThreadPool.submit(lineTask); } ThreadPool.waitFor(futures, pt); pt.finished(); return dest; }
Example 8
Source Project: openjdk-jdk8u File: PaletteBuilder.java License: GNU General Public License v2.0 | 5 votes |
protected int getBranchIndex(Color aColor, int aLevel) { if (aLevel > MAXLEVEL || aLevel < 0) { throw new IllegalArgumentException("Invalid octree node depth: " + aLevel); } int shift = MAXLEVEL - aLevel; int red_index = 0x1 & ((0xff & aColor.getRed()) >> shift); int green_index = 0x1 & ((0xff & aColor.getGreen()) >> shift); int blue_index = 0x1 & ((0xff & aColor.getBlue()) >> shift); int index = (red_index << 2) | (green_index << 1) | blue_index; return index; }
Example 9
Source Project: ChatGameFontificator File: Sprite.java License: The Unlicense | 5 votes |
private BufferedImage addToColorCache(Color drawColor) { for (short i = 0; i < 256; i++) { swapTable.getTable()[0][i] = (short) ((i / 255.0f) * drawColor.getRed()); swapTable.getTable()[1][i] = (short) ((i / 255.0f) * drawColor.getGreen()); swapTable.getTable()[2][i] = (short) ((i / 255.0f) * drawColor.getBlue()); } BufferedImage coloredImg = copyImage(img); coloredImg = swapOp.filter(img, coloredImg); coloredImgs.put(drawColor, coloredImg); return coloredImg; }
Example 10
Source Project: ghidra File: FcgEdgePaintTransformer.java License: Apache License 2.0 | 5 votes |
private Color[] alphatize(Color c) { Color[] alphad = new Color[10]; alphad[0] = c; for (int i = 1; i < 10; i++) { double newAlpha = 255 - (i * 25.5); alphad[i] = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) newAlpha); } return alphad; }
Example 11
Source Project: openjdk-jdk8u File: DerivedColor.java License: GNU General Public License v2.0 | 5 votes |
/** * Returns a string representation of this <code>Color</code>. This method * is intended to be used only for debugging purposes. The content and * format of the returned string might vary between implementations. The * returned string might be empty but cannot be <code>null</code>. * * @return a String representation of this <code>Color</code>. */ @Override public String toString() { Color src = UIManager.getColor(uiDefaultParentName); String s = "DerivedColor(color=" + getRed() + "," + getGreen() + "," + getBlue() + " parent=" + uiDefaultParentName + " offsets=" + getHueOffset() + "," + getSaturationOffset() + "," + getBrightnessOffset() + "," + getAlphaOffset(); return src == null ? s : s + " pColor=" + src.getRed() + "," + src.getGreen() + "," + src.getBlue(); }
Example 12
Source Project: jdk8u60 File: XArrayDataViewer.java License: GNU General Public License v2.0 | 4 votes |
public static Component loadArray(Object value) { Component comp = null; if (isViewableValue(value)) { Object[] arr; if (value instanceof Collection) { arr = ((Collection<?>) value).toArray(); } else if (value instanceof Map) { arr = ((Map<?,?>) value).entrySet().toArray(); } else if (value instanceof Object[]) { arr = (Object[]) value; } else { int length = Array.getLength(value); arr = new Object[length]; for (int i = 0; i < length; i++) { arr[i] = Array.get(value, i); } } JEditorPane arrayEditor = new JEditorPane(); arrayEditor.setContentType("text/html"); arrayEditor.setEditable(false); Color evenRowColor = arrayEditor.getBackground(); int red = evenRowColor.getRed(); int green = evenRowColor.getGreen(); int blue = evenRowColor.getBlue(); String evenRowColorStr = "rgb(" + red + "," + green + "," + blue + ")"; Color oddRowColor = new Color( red < 20 ? red + 20 : red - 20, green < 20 ? green + 20 : green - 20, blue < 20 ? blue + 20 : blue - 20); String oddRowColorStr = "rgb(" + oddRowColor.getRed() + "," + oddRowColor.getGreen() + "," + oddRowColor.getBlue() + ")"; Color foreground = arrayEditor.getForeground(); String textColor = String.format("%06x", foreground.getRGB() & 0xFFFFFF); StringBuilder sb = new StringBuilder(); sb.append("<html><body text=#"+textColor+"><table width=\"100%\">"); for (int i = 0; i < arr.length; i++) { if (i % 2 == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } else { sb.append("<tr style=\"background-color: " + oddRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } } if (arr.length == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td></td></tr>"); } sb.append("</table></body></html>"); arrayEditor.setText(sb.toString()); JScrollPane scrollp = new JScrollPane(arrayEditor); comp = scrollp; } return comp; }
Example 13
Source Project: mzmine2 File: GraphicsExportParameters.java License: GNU General Public License v2.0 | 4 votes |
public Color getColorWithAlpha() { Color c = getColor(); return new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255 * getTransparency())); }
Example 14
Source Project: hmftools File: ColorPicker.java License: GNU General Public License v3.0 | 4 votes |
@NotNull private static String toString(@NotNull final Color color) { return "color=(" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ")"; }
Example 15
Source Project: gama File: GamaColor.java License: GNU General Public License v3.0 | 4 votes |
public GamaColor(final Color c, final double alpha) { this(c.getRed(), c.getGreen(), c.getBlue(), normalize(alpha)); }
Example 16
Source Project: ghidra File: LayeredColorModel.java License: Apache License 2.0 | 4 votes |
private Color blend(Color primary, Color secondary) { int red = (primary.getRed() * 2 + secondary.getRed()) / 3; int green = (primary.getGreen() * 2 + secondary.getGreen()) / 3; int blue = (primary.getBlue() * 2 + secondary.getBlue()) / 3; return new Color(red, green, blue); }
Example 17
Source Project: TencentKona-8 File: XArrayDataViewer.java License: GNU General Public License v2.0 | 4 votes |
public static Component loadArray(Object value) { Component comp = null; if (isViewableValue(value)) { Object[] arr; if (value instanceof Collection) { arr = ((Collection<?>) value).toArray(); } else if (value instanceof Map) { arr = ((Map<?,?>) value).entrySet().toArray(); } else if (value instanceof Object[]) { arr = (Object[]) value; } else { int length = Array.getLength(value); arr = new Object[length]; for (int i = 0; i < length; i++) { arr[i] = Array.get(value, i); } } JEditorPane arrayEditor = new JEditorPane(); arrayEditor.setContentType("text/html"); arrayEditor.setEditable(false); Color evenRowColor = arrayEditor.getBackground(); int red = evenRowColor.getRed(); int green = evenRowColor.getGreen(); int blue = evenRowColor.getBlue(); String evenRowColorStr = "rgb(" + red + "," + green + "," + blue + ")"; Color oddRowColor = new Color( red < 20 ? red + 20 : red - 20, green < 20 ? green + 20 : green - 20, blue < 20 ? blue + 20 : blue - 20); String oddRowColorStr = "rgb(" + oddRowColor.getRed() + "," + oddRowColor.getGreen() + "," + oddRowColor.getBlue() + ")"; Color foreground = arrayEditor.getForeground(); String textColor = String.format("%06x", foreground.getRGB() & 0xFFFFFF); StringBuilder sb = new StringBuilder(); sb.append("<html><body text=#"+textColor+"><table width=\"100%\">"); for (int i = 0; i < arr.length; i++) { if (i % 2 == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } else { sb.append("<tr style=\"background-color: " + oddRowColorStr + "\"><td><pre>" + (arr[i] == null ? arr[i] : htmlize(arr[i].toString())) + "</pre></td></tr>"); } } if (arr.length == 0) { sb.append("<tr style=\"background-color: " + evenRowColorStr + "\"><td></td></tr>"); } sb.append("</table></body></html>"); arrayEditor.setText(sb.toString()); JScrollPane scrollp = new JScrollPane(arrayEditor); comp = scrollp; } return comp; }
Example 18
Source Project: pumpernickel File: HSLColor.java License: MIT License | 4 votes |
/** * Convert a RGB Color to it corresponding HSL values. * * @param color * the color to convert. * @param dest * the optional array to store the result in. * @return an array containing the 3 HSL values. */ public static float[] fromRGB(Color color, float[] dest) { // Get RGB values in the range 0 - 1 float r = (color.getRed()) / 255f; float g = (color.getGreen()) / 255f; float b = (color.getBlue()) / 255f; // Minimum and Maximum RGB values are used in the HSL calculations float min = Math.min(r, Math.min(g, b)); float max = Math.max(r, Math.max(g, b)); // Calculate the Hue float h = 0; if (max == min) h = 0; else if (max == r) h = (((g - b) / (max - min) / 6f) + 1) % 1; else if (max == g) h = ((b - r) / (max - min) / 6f) + 1f / 3f; else if (max == b) h = ((r - g) / (max - min) / 6f) + 2f / 3f; // Calculate the Luminance float l = (max + min) / 2; // Calculate the Saturation float s = 0; if (max == min) s = 0; else if (l <= .5f) s = (max - min) / (max + min); else s = (max - min) / (2 - max - min); if (dest == null) dest = new float[3]; dest[0] = h; dest[1] = s; dest[2] = l; return dest; }
Example 19
Source Project: jdk8u60 File: XComponentPeer.java License: GNU General Public License v2.0 | 3 votes |
static int[] getRGBvals(Color c) { int rgbvals[] = new int[3]; rgbvals[0] = c.getRed(); rgbvals[1] = c.getGreen(); rgbvals[2] = c.getBlue(); return rgbvals; }
Example 20
Source Project: 07kit File: ColorUtil.java License: GNU General Public License v3.0 | 2 votes |
/** * Creates a new {@link Color} with RGB from <code>color</code> and the alpha value of <code>alpha</code> * @param color {@link Color} you want to have with <code>alpha</code> * @param alpha alpha value you want to set. Must be between 0f and 1f * @return new {@link Color} with <code>alpha</code> */ public static Color withAlpha(Color color, float alpha) { final int newAlpha = floatAlphaToIntAlpha(alpha); return new Color(color.getRed(), color.getGreen(), color.getBlue(), newAlpha); }