parse Color to float Array - Android Graphics

Android examples for Graphics:Color Value

Description

parse Color to float Array

Demo Code


//package com.java2s;
import android.graphics.Color;

public class Main {

    public static float[] parseColor2Array(String colorStr) {
        float[] colorArray = new float[3];
        int color = parseColor(colorStr);
        colorArray[0] = (1.0f * Color.red(color)) / 255.0f;
        colorArray[1] = (1.0f * Color.green(color)) / 255.0f;
        colorArray[2] = (1.0f * Color.blue(color)) / 255.0f;
        return colorArray;
    }//from w  w  w  .j ava  2s.com

    public static int parseColor(String colorStr) {
        int color = 0xff000000;
        try {
            color = Color.parseColor(colorStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return color;
    }
}

Related Tutorials