Converts a color into a String like 255,0,0. - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

Converts a color into a String like 255,0,0.

Demo Code

/**/*  w  w w .  ja v  a2 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.
     * @param color   Color to convert into a String.
     * @return String color RGB String.
     */
    public static String colorToRGBString(Color color) {
        String rgb = "";
        if (color != null) {
            rgb = color.getRed() + "," + color.getGreen() + ","
                    + color.getBlue();
        }
        return rgb;
    }
}

Related Tutorials