List of usage examples for java.awt Color getColorComponents
public float[] getColorComponents(float[] compArray)
From source file:Main.java
public static void main(String[] args) { Color myColor = Color.RED; System.out.println(Arrays.toString(myColor.getColorComponents(null))); }
From source file:Main.java
public static void main(String[] args) { Color myColor = new Color(ColorSpace.getInstance(ColorSpace.CS_CIEXYZ), new float[] { 0.1F, 0.2F, 0.3F }, 0.4F);/*from ww w. j a v a 2 s . com*/ System.out.println(Arrays.toString(myColor.getColorComponents(null))); }
From source file:algorithms.MedianDivergenceComputer.java
public static PColor convert(Color color) { return PColor.create(CS_sRGB.instance, color.getColorComponents(new float[3])); }
From source file:D20140128.ApacheXMLGraphicsTest.EPSColorsExample.java
/** * Creates an EPS file. The contents are painted using a Graphics2D * implementation that generates an EPS file. * * @param outputFile the target file//from ww w .jav a 2 s . c o m * @throws IOException In case of an I/O error */ public static void generateEPSusingJava2D(File outputFile) throws IOException { OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { //Instantiate the EPSDocumentGraphics2D instance EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); //Set up the document size g2d.setupDocument(out, 400, 200); //400pt x 200pt //Paint a bounding box g2d.drawRect(0, 0, 400, 200); g2d.setFont(new Font("sans-serif", Font.BOLD, 14)); g2d.drawString("Color usage example:", 10, 20); g2d.setFont(new Font("sans-serif", Font.PLAIN, 12)); g2d.drawString("RGB", 10, 84); g2d.drawString("CMYK", 60, 84); g2d.drawString("(Lab)", 110, 84); g2d.drawString("(Named)", 160, 84); //We're creating a few boxes all filled with some variant of the //"Postgelb" (postal yellow) color as used by Swiss Post. Color colRGB = new Color(255, 204, 0); g2d.setColor(colRGB); g2d.fillRect(10, 30, 40, 40); //Just convert RGB to CMYK and use that float[] compsRGB = colRGB.getColorComponents(null); DeviceCMYKColorSpace cmykCS = ColorSpaces.getDeviceCMYKColorSpace(); float[] compsCMYK = cmykCS.fromRGB(compsRGB); Color colCMYK = DeviceCMYKColorSpace.createCMYKColor(compsCMYK); g2d.setColor(colCMYK); g2d.fillRect(60, 30, 40, 40); //Try CIELab (not implemented, yet) CIELabColorSpace d50 = ColorSpaces.getCIELabColorSpaceD50(); Color colLab = d50.toColor(83.25f, 16.45f, 96.89f, 1.0f); g2d.setColor(colLab); g2d.fillRect(110, 30, 40, 40); //Try named color (Separation, not implemented, yet) float[] c1xyz = d50.toCIEXYZNative(83.25f, 16.45f, 96.89f); NamedColorSpace postgelb = new NamedColorSpace("Postgelb", c1xyz); Color colNamed = new Color(postgelb, new float[] { 1.0f }, 1.0f); g2d.setColor(colNamed); g2d.fillRect(160, 30, 40, 40); //Cleanup g2d.finish(); } finally { IOUtils.closeQuietly(out); } }
From source file:ColorUtil.java
/** * Return the "distance" between two colors. * /*from w w w .ja v a 2 s. c o m*/ * @param color1 First color. * @param color2 Second color. * @return Distance between colors. */ public static double colorDistance(Color color1, Color color2) { float rgb1[] = new float[3]; float rgb2[] = new float[3]; color1.getColorComponents(rgb1); color2.getColorComponents(rgb2); return ColorUtil.colorDistance(rgb1[0], rgb1[1], rgb1[2], rgb2[0], rgb2[1], rgb2[2]); }
From source file:gate.termraider.output.CloudGenerator.java
private static Color blend(Color clOne, Color clTwo, float fAmount) { float fInverse = 1.0f - fAmount; float afOne[] = new float[3]; clOne.getColorComponents(afOne); float afTwo[] = new float[3]; clTwo.getColorComponents(afTwo);/*from www. ja v a 2 s . co m*/ float afResult[] = new float[3]; afResult[0] = afOne[0] * fAmount + afTwo[0] * fInverse; afResult[1] = afOne[1] * fAmount + afTwo[1] * fInverse; afResult[2] = afOne[2] * fAmount + afTwo[2] * fInverse; return new Color(afResult[0], afResult[1], afResult[2]); }
From source file:java2d.ps.EPSColorsExample.java
/** * Creates an EPS file. The contents are painted using a Graphics2D * implementation that generates an EPS file. * // ww w .j a va 2 s . c o m * @param outputFile * the target file * @throws IOException * In case of an I/O error */ public static void generateEPSusingJava2D(final File outputFile) throws IOException { OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { // Instantiate the EPSDocumentGraphics2D instance final EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); // Set up the document size g2d.setupDocument(out, 400, 200); // 400pt x 200pt // Paint a bounding box g2d.drawRect(0, 0, 400, 200); g2d.setFont(new Font("sans-serif", Font.BOLD, 14)); g2d.drawString("Color usage example:", 10, 20); g2d.setFont(new Font("sans-serif", Font.PLAIN, 12)); g2d.drawString("RGB", 10, 84); g2d.drawString("CMYK", 60, 84); g2d.drawString("(Lab)", 110, 84); g2d.drawString("(Named)", 160, 84); // We're creating a few boxes all filled with some variant of the // "Postgelb" (postal yellow) color as used by Swiss Post. final Color colRGB = new Color(255, 204, 0); g2d.setColor(colRGB); g2d.fillRect(10, 30, 40, 40); // Just convert RGB to CMYK and use that final float[] compsRGB = colRGB.getColorComponents(null); final DeviceCMYKColorSpace cmykCS = ColorSpaces.getDeviceCMYKColorSpace(); final float[] compsCMYK = cmykCS.fromRGB(compsRGB); final Color colCMYK = DeviceCMYKColorSpace.createCMYKColor(compsCMYK); g2d.setColor(colCMYK); g2d.fillRect(60, 30, 40, 40); // Try CIELab (not implemented, yet) final CIELabColorSpace d50 = ColorSpaces.getCIELabColorSpaceD50(); final Color colLab = d50.toColor(83.25f, 16.45f, 96.89f, 1.0f); g2d.setColor(colLab); g2d.fillRect(110, 30, 40, 40); // Try named color (Separation, not implemented, yet) final float[] c1xyz = d50.toCIEXYZNative(83.25f, 16.45f, 96.89f); final NamedColorSpace postgelb = new NamedColorSpace("Postgelb", c1xyz); final Color colNamed = new Color(postgelb, new float[] { 1.0f }, 1.0f); g2d.setColor(colNamed); g2d.fillRect(160, 30, 40, 40); // Cleanup g2d.finish(); } finally { IOUtils.closeQuietly(out); } }
From source file:ColorUtil.java
/** * Blend two colors./*from w w w.j ava 2 s. com*/ * * @param color1 First color to blend. * @param color2 Second color to blend. * @param ratio Blend ratio. 0.5 will give even blend, 1.0 will return * color1, 0.0 will return color2 and so on. * @return Blended color. */ public static Color blend(Color color1, Color color2, double ratio) { float r = (float) ratio; float ir = (float) 1.0 - r; float rgb1[] = new float[3]; float rgb2[] = new float[3]; color1.getColorComponents(rgb1); color2.getColorComponents(rgb2); Color color = new Color(rgb1[0] * r + rgb2[0] * ir, rgb1[1] * r + rgb2[1] * ir, rgb1[2] * r + rgb2[2] * ir); return color; }
From source file:de.saring.util.gui.jfreechart.StackedRenderer.java
/** * Returns the paint used to fill an item drawn by the renderer. * Overridden for proper display of legend items * * @param series the series index (zero-based). * @return The paint (never <code>null</code>). *//*from www .j ava 2s .co m*/ @Override public Paint lookupSeriesPaint(int series) { Paint paint = super.lookupSeriesPaint(series); if (paint instanceof Color) { Color color = (Color) paint; paint = new Color(color.getColorSpace(), color.getColorComponents(null), areaAlpha); } return paint; }
From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java
/** * Set the stroking color, specified as RGB. * /*ww w. j ava 2 s .co m*/ * @param color * The color to set. * @throws IOException * If an IO error occurs while writing to the stream. */ public void setStrokingColor(Color color) throws IOException { ColorSpace colorSpace = color.getColorSpace(); if (colorSpace.getType() == ColorSpace.TYPE_RGB) { setStrokingColor(color.getRed(), color.getGreen(), color.getBlue()); } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) { color.getColorComponents(colorComponents); setStrokingColor(colorComponents[0]); } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) { color.getColorComponents(colorComponents); setStrokingColor(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]); } else { throw new IOException("Error: unknown colorspace:" + colorSpace); } }