Java Hex Convert To fromHexString(String hexString)

Here you can find the source of fromHexString(String hexString)

Description

Transforms a color rgba hex string representation to its rgba components.

License

Open Source License

Parameter

Parameter Description
hexString the Hex string representation argb coded.

Return

the rgba components of the color once parsed in an array.

Declaration

public static int[] fromHexString(String hexString) 

Method Source Code

//package com.java2s;
/*/*w  ww. j  a va  2s  .  c om*/
 * Copyright (c) 2005-2016 Vincent Vandenschrick. All rights reserved.
 *
 *  This file is part of the Jspresso framework.
 *
 *  Jspresso is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Jspresso is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Jspresso.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Transforms a color rgba hex string representation to its rgba components.
     *
     * @param hexString
     *          the Hex string representation argb coded.
     * @return the rgba components of the color once parsed in an array.
     */
    public static int[] fromHexString(String hexString) {
        int[] rgba = new int[4];
        int offset = 0;
        if (hexString.length() == 10) {
            rgba[3] = Integer.parseInt(hexString.substring(2, 4), 16);
            offset = 2;
        } else {
            // to support un-existing alpha
            rgba[3] = Integer.parseInt("FF", 16);
        }
        rgba[0] = Integer.parseInt(hexString.substring(2 + offset, 4 + offset), 16);
        rgba[1] = Integer.parseInt(hexString.substring(4 + offset, 6 + offset), 16);
        rgba[2] = Integer.parseInt(hexString.substring(6 + offset, 8 + offset), 16);
        return rgba;
    }
}

Related

  1. fromHexString(String hex)
  2. fromHexString(String hex)
  3. fromHexString(String hexString)
  4. fromHexString(String hexString)
  5. fromHexString(String hexString)
  6. fromHexString(String in)
  7. fromHexString(String input)
  8. fromHexString(String input)
  9. fromHexString(String input)