Java Color Encode encodeRGBIntString(Color color, boolean withAlpha)

Here you can find the source of encodeRGBIntString(Color color, boolean withAlpha)

Description

Create a string of the integer values of the RGB components of the color.

License

Apache License

Parameter

Parameter Description
color the color to encode
withAlpha whether the alpha value should be appended

Return

the string or null if color was null

Declaration

public static String encodeRGBIntString(Color color, boolean withAlpha) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.Color;

public class Main {
    /**/*from   w ww.  j  a  v  a 2  s  .co m*/
     * Create a string of the integer values of the RGB components of the color. The components are
     * separated by comma.
     *
     * @param color
     *            the color to encode
     * @param withAlpha
     *            whether the alpha value should be appended
     * @return the string or null if color was null
     */
    public static String encodeRGBIntString(Color color, boolean withAlpha) {
        if (color == null) {
            return null;
        }
        StringBuilder colorString = new StringBuilder();
        colorString.append(color.getRed()).append(",").append(color.getGreen()).append(",").append(color.getBlue());
        if (withAlpha) {
            colorString.append(",").append(color.getAlpha());
        }
        return colorString.toString();
    }
}

Related

  1. encodeColor(Color color)
  2. encodeColor(int r, int g, int b)
  3. encodeColorForCss(Color color)
  4. encodeRGB(Color color)
  5. encodeRGBHexString(Color color, boolean withAlpha)