to Browser Color - Android Graphics

Android examples for Graphics:Color

Description

to Browser Color

Demo Code


//package com.java2s;

public class Main {

    public static String toBrowserColor(int color) {
        int red = getRed(color);
        int green = getGreen(color);
        int blue = getBlue(color);

        String redStr = ((red + "").length() < 2 ? red + "0" : red + "");
        String greenStr = ((green + "").length() < 2 ? green + "0" : green
                + "");
        String blueStr = ((blue + "").length() < 2 ? blue + "0" : blue + "");

        return "#" + redStr + blueStr + greenStr;
    }/*from  w  ww . j a  v a 2 s . c  o m*/

    public static int getRed(int color) {
        int red = (color & 0xff0000) >> 16;
        return red;
    }

    public static int getGreen(int color) {
        int green = (color & 0x00ff00) >> 8;
        return green;
    }

    public static int getBlue(int color) {
        int blue = (color & 0x0000ff);
        return blue;
    }
}

Related Tutorials