Java Color Decode decode(String color)

Here you can find the source of decode(String color)

Description

decode

License

Open Source License

Declaration

private static Color decode(String color) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;

public class Main {
    private static Color decode(String color) {
        /** http://code.google.com/apis/kml/documentation/kmlreference.html#colorstyle
         * Color and opacity (alpha) values are expressed in hexadecimal notation. 
         * The range of values for any one color is 0 to 255 (00 to ff). 
         * For alpha, 00 is fully transparent and ff is fully opaque. 
         * The order of expression is aabbggrr, where aa=alpha (00 to ff); bb=blue (00 to ff); 
         * gg=green (00 to ff); rr=red (00 to ff). 
         * For example, if you want to apply a blue color with 50 percent opacity to an overlay, 
         * you would specify the following: <color>7fff0000</color>, where 
         * alpha=0x7f, blue=0xff, green=0x00, and red=0x00.
         *//*from  w w  w. j  a v a2 s  . co  m*/
        long i = Long.parseLong(color, 16);
        int r = (int) (i & 0xff);
        int g = (int) ((i >> 8) & 0xff);
        int b = (int) ((i >> 16) & 0xff);
        int a = (int) ((i >> 24) & 0xff);
        return new Color(r, g, b, a);
    }
}

Related

  1. decodeColor(final double v)
  2. decodeColor(final String value)
  3. decodeColor(int color)
  4. decodeColor(int value)