Refine search
public static void main(String... args) throws Exception { BufferedImage image = ImageIO.read( new URL("http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png")); int w = image.getWidth(); int h = image.getHeight(); int[] dataBuffInt = image.getRGB(0, 0, w, h, null, 0, w); Color c = new Color(dataBuffInt[100]); System.out.println(c.getRed()); // = (dataBuffInt[100] >> 16) & 0xFF System.out.println(c.getGreen()); // = (dataBuffInt[100] >> 8) & 0xFF System.out.println(c.getBlue()); // = (dataBuffInt[100] >> 0) & 0xFF System.out.println(c.getAlpha()); // = (dataBuffInt[100] >> 24) & 0xFF }
fraction = Math.max(fraction, 0f); final float RED1 = COLOR1.getRed() * INT_TO_FLOAT_CONST; final float GREEN1 = COLOR1.getGreen() * INT_TO_FLOAT_CONST; final float BLUE1 = COLOR1.getBlue() * INT_TO_FLOAT_CONST; final float ALPHA1 = COLOR1.getAlpha() * INT_TO_FLOAT_CONST; final float RED2 = COLOR2.getRed() * INT_TO_FLOAT_CONST; final float GREEN2 = COLOR2.getGreen() * INT_TO_FLOAT_CONST; final float BLUE2 = COLOR2.getBlue() * INT_TO_FLOAT_CONST; final float ALPHA2 = COLOR2.getAlpha() * INT_TO_FLOAT_CONST; alpha = Math.max(alpha, 0f); return new Color((new java.awt.Color(red, green, blue, alpha)).getRGB());
private void updateFill() { final boolean isFullyTransparent = marker.getMarker().getFill().getAlpha() == 0; if (isFullyTransparent) { fillColorIndicator.setBorder(null); } else { Color color = marker.getMarker().getFill(); Color fullColor = new Color(color.getRed(), color.getGreen(), color.getBlue()); fillColorIndicator.setBorder(new MatteBorder(0, 0, 3, 0, fullColor)); } fillColorIndicator.setIcon(isFullyTransparent ? NO_FILL_COLOR_ICON : FILL_COLOR_ICON); opacityIndicator.setIcon(isFullyTransparent ? NO_OPACITY_ICON : FULL_OPACITY_ICON); }
private void colorChange(Color newColor) { if (newColor == this.selectedColor) { return; } this.selectedColor = newColor; // Finally, before firing the color changed event, apply any transparency // that might have been edited by the user if (this.selectedColor.getAlpha() != this.alphaSlider.getValue()) { this.selectedColor = new Color( selectedColor.getRed(), selectedColor.getGreen(), selectedColor.getBlue(), alphaSlider.getValue()); } updateText(); if (onColorChange != null) { onColorChange.accept(this.selectedColor); } }
@Override public void mousePressed(MouseEvent mouseEvent) { final Color fill = marker.getMarker().getFill(); if (fill.getAlpha() == 0) { marker.getMarker().setFill(new Color(fill.getRed(), fill.getGreen(), fill.getBlue(), DEFAULT_FILL_OPACITY)); } else { marker.getMarker().setFill(new Color(fill.getRed(), fill.getGreen(), fill.getBlue(), 0)); } updateFill(); plugin.updateConfig(); }
private void updateText() { String hex = alphaHidden ? ColorUtil.colorToHexCode(this.getSelectedColor()) : ColorUtil.colorToAlphaHexCode(this.getSelectedColor()); hexInput.setText(hex.toUpperCase()); afterPanel.setColor(selectedColor); redSlider.update(this.selectedColor.getRed()); greenSlider.update(this.selectedColor.getGreen()); blueSlider.update(this.selectedColor.getBlue()); if (!alphaHidden) { alphaSlider.update(this.selectedColor.getAlpha()); } }
for (int i = 0; i < 28; i++) { palette[i + 00] = new Color(ALPHA & Color.HSBtoRGB(0.333f, i * 0.037f, 0.8f), true); // Green palette[i + 30] = new Color(ALPHA & Color.HSBtoRGB(0.666f, i * 0.037f, 0.8f), true); // Blue palette[i + 60] = new Color(ALPHA & Color.HSBtoRGB(0.144f, i * 0.037f, 0.8f), true); // Yellow palette[i + 90] = new Color(ALPHA & Color.HSBtoRGB(0.000f, i * 0.037f, 0.8f), true); // Red palette[i + 120] = new Color(ALPHA & Color.HSBtoRGB(0.000f, 0.000f, (29 - i) * 0.0172f), true); // Black byte[] a = new byte[256]; for (int i = 0; i < palette.length; i++) { r[i] = (byte)palette[i].getRed(); g[i] = (byte)palette[i].getGreen(); b[i] = (byte)palette[i].getBlue(); a[i] = (byte)palette[i].getAlpha();
/** * Create a new color with the the given color. * <p/> * The color object is cloned; you can change the original afterwards. * If the color object is null, the new color is turned off (same as nocolor). * * @param color the color object. */ public Color(java.awt.Color color) { this(color.getRed() / 255.0, color.getGreen() / 255.0, color.getBlue() / 255.0, color.getAlpha() / 255.0); }
public static Color abitbrighter(Color c) { int r = c.getRed(); int g = c.getGreen(); int b = c.getBlue(); int alpha = c.getAlpha(); int plus_r = (int) ((255 - r) / 2); int plus_g = (int) ((255 - g) / 2); int plus_b = (int) ((255 - b) / 2); return new Color(r + plus_r, g + plus_g, b + plus_b, alpha); }
protected Color mix(Color color1, Color color2, double weight) { // adjust weight based on alpha double da = color1.getAlpha() - color2.getAlpha(); double w = weight * 2 - 1; double w1 = (((w * da == -1) ? w : (w + da) / (1 + w * da)) + 1) / 2.0; double w2 = 1 - w1; // mix colors int red = (int) Math.round(color1.getRed() * w1 + color2.getRed() * w2); int green = (int) Math.round(color1.getGreen() * w1 + color2.getGreen() * w2); int blue = (int) Math.round(color1.getBlue() * w1 + color2.getBlue() * w2); int alpha = 255; if (color1.getAlpha() < 255 || color2.getAlpha() < 255) { alpha = (int) Math.round(color1.getAlpha() * weight + color2.getAlpha() * (1 - weight)); } return new Color(red, green, blue, alpha); } }