Converts a color into a String like "255,0,0,255" (red,green,blue,alpha). - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

Converts a color into a String like "255,0,0,255" (red,green,blue,alpha).

Demo Code

/**//from w ww  .j a v a  2 s  . co  m
 * Copyright 1998-2008, CHISEL Group, University of Victoria, Victoria, BC, Canada.
 * All rights reserved.
 */
//package com.java2s;
import java.awt.Color;

public class Main {
    /**
     * Converts a color into a String like "255,0,0,255" (red,green,blue,alpha).
     * @param color   Color to convert into a String.
     * @return String color RGB String or the empty string
     */
    public static String colorToRGBAString(Color color) {
        String rgba = "";
        if (color != null) {
            rgba = color.getRed() + "," + color.getGreen() + ","
                    + color.getBlue() + "," + color.getAlpha();
        }
        return rgba;
    }
}

Related Tutorials