Java RGB Color Convert To RGBtoInt(String rgb)

Here you can find the source of RGBtoInt(String rgb)

Description

RG Bto Int

License

Open Source License

Declaration

public static int RGBtoInt(String rgb) 

Method Source Code

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

public class Main {
    public static int RGBtoInt(String rgb) {
        int r = Integer.parseInt(getR(rgb), 16);
        int g = Integer.parseInt(getG(rgb), 16);
        int b = Integer.parseInt(getB(rgb), 16);

        int clr = r;
        clr = clr << 8 | g;/*w w w .  j  a  v a2s  .  c  om*/
        clr = clr << 8 | b;
        return clr;
    }

    public static String getR(String rgb) {
        if (rgb.length() < 2)
            return "00";
        return rgb.substring(0, 2);
    }

    public static String getG(String rgb) {
        if (rgb.length() < 4)
            return "00";
        return rgb.substring(2, 4);
    }

    public static String getB(String rgb) {
        if (rgb.length() < 6)
            return "00";
        return rgb.substring(4, 6);
    }
}

Related

  1. rgbToHsv(int rgb)
  2. RGBtoHTML(int rgb)
  3. RGBToInt(float[] rgb)
  4. RGBtoInt(int r, int g, int b)
  5. RGBtoInt(int red, int green, int blue)
  6. RGBToInteger(int red, int green, int blue)
  7. rgbToShort(int rgb)
  8. rgbToString(float r, float g, float b)
  9. rgbToText(int red, int green, int blue)