Java Color to RGB String toRGB(ColorSpace colorSpace, float... components)

Here you can find the source of toRGB(ColorSpace colorSpace, float... components)

Description

Returns an rgb value from color components in the specified color space.

License

Open Source License

Declaration

public static int toRGB(ColorSpace colorSpace, float... components) 

Method Source Code

//package com.java2s;
/*//from   w w w .  ja v a 2 s  .  co  m
 * @(#)ColorUtil.java
 * 
 * Copyright (c) 2010 by the original authors of JHotDraw and all its
 * contributors. All rights reserved.
 * 
 * You may not use, copy or modify this file, except in compliance with the 
 * license agreement you entered into with the copyright holders. For details
 * see accompanying license terms.
 */

import java.awt.color.ColorSpace;

public class Main {
    /** Returns an rgb value from color components in the specified color space.
     */
    public static int toRGB(ColorSpace colorSpace, float... components) {
        float[] rgb = colorSpace.toRGB(components);

        // If the color is not displayable in RGB, we return transparent black.
        if (rgb[0] < 0f || rgb[1] < 0f || rgb[2] < 0f || rgb[0] > 1f
                || rgb[1] > 1f || rgb[2] > 1f) {
            return 0;
        }
        return 0xff000000 | ((int) (rgb[0] * 255f) << 16)
                | ((int) (rgb[1] * 255f) << 8) | (int) (rgb[2] * 255f);
    }
}

Related

  1. colourToRgbString(Color colour)
  2. colourToString(Color colour)
  3. colourToString(java.awt.Color c)
  4. toRGB(Color c)
  5. toRGB(Color color)
  6. toRGB(int red, int green, int blue)
  7. toRGB565(Color c)
  8. toRGBA(Color c)
  9. toRGBFunctionCall(Color color)