Java Color Convert To colorToString(int color, boolean rgb)

Here you can find the source of colorToString(int color, boolean rgb)

Description

color To String

License

Open Source License

Declaration

static public String colorToString(int color, boolean rgb) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final int BLUE_MASK = 0xff;
    public static final int GREEN_MASK = 0xff00;
    public static final int RED_MASK = 0xff0000;
    public static final int GREEN_OFFSET = 8;
    public static final int RED_OFFSET = 16;

    static public String colorToString(int color, boolean rgb) {
        String result = null;//from   w ww.  java2s  .  c o  m
        if (rgb) {
            result = "" + splitRed(color) + ", " + splitGreen(color) + ", " + splitBlue(color);
        } else
            result = "" + color;
        return result;
    }

    /** Split red from int. */
    static public int splitRed(int colorIn) {
        return (colorIn & RED_MASK) >> RED_OFFSET; //red
    }

    /** Split green from int. */
    static public int splitGreen(int colorIn) {
        return (colorIn & GREEN_MASK) >> GREEN_OFFSET; //green
    }

    /** Split blue from int. */
    static public int splitBlue(int colorIn) {
        return colorIn & BLUE_MASK; //blue
    }
}

Related

  1. colorToFloat(int color)
  2. colorToHex(int color)
  3. colorToHex(int integer)
  4. colorToRGB(final int alpha, final int red, final int green, final int blue)
  5. colorToStringHex(int red, int green, int blue)