parse RGB Color - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

parse RGB Color

Demo Code


//package com.java2s;
import java.awt.Color;

public class Main {
    public static Color parseRGBColor(String str) {
        if (str.startsWith("0x")) {
            try {
                return new Color(Integer.valueOf(str.substring(2), 16));
            } catch (NumberFormatException e) {
                e.printStackTrace();/*from   w  ww  .j ava 2 s . c om*/
            }
        }
        if (str.startsWith("#")) {
            try {
                return new Color(Integer.valueOf(str.substring(1), 16));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}

Related Tutorials