List of usage examples for java.awt Color Color
public Color(int rgb)
From source file:Main.java
/** * Parse string value as Color. Return default value if source * string is null./*from ww w . ja v a2 s.co m*/ * @param value String * @param defValue Color * @return Color */ public static Color getAsColor(String value, Color defValue) { Color result = defValue; if (value != null) { try { result = new Color(Integer.parseInt(value, 16)); } catch (NumberFormatException ex) { } } return result; }
From source file:Main.java
public static Color getTableBackgroundColor(boolean colored) { if (colored)/*from ww w .j a va 2 s . c om*/ return new Color(0xf4f4f4); return UIManager.getColor("Table.background"); }
From source file:Main.java
/** * Generates a list of colors. The result is always identical. * /*from w w w. java 2 s . c o m*/ * @param amount The number of colors to calculate. * @return A list of colors. Never returns <code>null</code>. * @see https://stackoverflow.com/questions/3403826/how-to-dynamically-compute-a-list-of-colors */ private static List<Color> calculateUniqueColors(int amount) { final int lowerLimit = 0x10; final int upperLimit = 0xE0; final int colorStep = (int) ((upperLimit - lowerLimit) / Math.pow(amount, 1f / 3)); final List<Color> colors = new ArrayList<>(amount); for (int R = lowerLimit; R < upperLimit; R += colorStep) for (int G = lowerLimit; G < upperLimit; G += colorStep) for (int B = lowerLimit; B < upperLimit; B += colorStep) { if (colors.size() >= amount) { // The calculated step is not very precise, so this safeguard is appropriate return colors; } else { int color = (R << 16) + (G << 8) + (B); colors.add(new Color(color)); } } return colors; }
From source file:MyCanvas.java
public MyCanvas() { int rgb = 0xff; for (int i = 0; i < 24; i++) { colors[i] = new Color(rgb); rgb <<= 1;/*w w w. j a v a 2 s . c o m*/ if ((rgb & 0x1000000) != 0) { rgb |= 1; rgb &= 0xffffff; } } }
From source file:imageprocessingproject.ImageHistogram.java
public static BufferedImage normalizeImage(BufferedImage image) { int height = image.getHeight(); int width = image.getWidth(); int r, g, b, minr = 255, ming = 255, minb = 255, maxr = 0, maxg = 0, maxb = 0; Color c;/*from ww w . ja va 2 s. com*/ 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)); if (minr > c.getRed()) { minr = c.getRed(); } if (ming > c.getGreen()) { ming = c.getGreen(); } if (minb > c.getBlue()) { minb = c.getBlue(); } if (maxr < c.getRed()) { maxr = c.getRed(); } if (maxg < c.getGreen()) { maxg = c.getGreen(); } if (maxb < c.getBlue()) { maxb = c.getBlue(); } } } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { c = new Color(image.getRGB(i, j)); r = (int) ((c.getRed() - minr) * 255 / (maxr - minr)); g = (int) ((c.getGreen() - ming) * 255 / (maxg - ming)); b = (int) ((c.getBlue() - minb) * 255 / (maxb - minb)); tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB()); } } return tempImage; }
From source file:app.utils.ImageUtilities.java
public static Image readImageFromFile(File imgFile) throws IOException { String imgName = imgFile.getName(); BufferedImage img = ImageIO.read(imgFile); Pixel[][] pixels = new Pixel[img.getWidth()][img.getHeight()]; for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { int redValue = new Color(img.getRGB(x, y)).getRed(); int greenValue = new Color(img.getRGB(x, y)).getGreen(); int blueValue = new Color(img.getRGB(x, y)).getBlue(); pixels[x][y] = new Pixel(redValue, greenValue, blueValue); }/* w w w . j av a 2 s .c o m*/ } return new Image(imgName, pixels, img.getRaster().getNumDataElements()); }
From source file:MainClass.java
public void paint(Graphics g) { int n = 3;/*from w w w . ja v a2s .c om*/ int xdata[] = new int[n]; int ydata[] = new int[n]; xdata[0] = 50; ydata[0] = 150; xdata[1] = 200; ydata[1] = 50; xdata[2] = 350; ydata[2] = 150; int rgb = Color.HSBtoRGB(1.0f, 1.0f, 1.0f); g.setColor(new Color(rgb)); g.fillPolygon(xdata, ydata, n); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { Rectangle clip = g.getClipBounds(); g.setColor(new Color(new Random().nextInt())); g.fillRect(clip.x, clip.y, clip.width, clip.height); }
From source file:Main.java
public CirclePanel() { this.setPreferredSize(new Dimension(80, 80)); this.setForeground(new Color(r.nextInt())); this.addMouseListener(new MouseAdapter() { @Override// ww w .j ava 2s .c o m public void mousePressed(MouseEvent e) { update(); } }); }
From source file:de.cgarbs.lib.json.type.JSONTypeFactoryTest.java
@Test public void checkWrapJavaObject() throws JSONException { assertThat(JSONTypeFactory.wrapJavaObject(new Color(0)), is(instanceOf(JSONColor.class))); }