Git Product home page Git Product logo

Comments (2)

jaredrummler avatar jaredrummler commented on August 26, 2024

I think this is what you are looking for: https://developer.android.com/reference/android/graphics/Color.html#alpha(int)

from colorpicker.

lozn00 avatar lozn00 commented on August 26, 2024

thank ,i donknow use ,because I use A = Integer.toHexString(Color.alpha(color)); show exception,
but I solved the problem by doing the following

    @NonNull
    private String getHexColorByIntColor(boolean needAppendAlpha) {
        String defaultAlpha = "ff";
        if (needAppendAlpha) {
            try {
                Field fieldAplha = colorPickerView.getClass().getDeclaredField("alpha");
                fieldAplha.setAccessible(true);
                int o = fieldAplha.getInt(colorPickerView);
                defaultAlpha = Integer.toHexString(o);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        } else {
            defaultAlpha = "";
        }
        return toHexEncoding(colorPickerView.getColor(), defaultAlpha);
    }


    public static String toHexEncoding(int color, String defaultAlpha) {
        String R, G, B, A;
        StringBuffer sb = new StringBuffer();
        A = color + "".length() == 8 ? Integer.toHexString(Color.alpha(color)) : "" + defaultAlpha;
        R = Integer.toHexString(Color.red(color));
        G = Integer.toHexString(Color.green(color));
        B = Integer.toHexString(Color.blue(color));
        //判断获取到的R,G,B值的长度 如果长度等于1 给R,G,B值的前边添0
        A = A.length() == 1 ? "0" + A : A;
        R = R.length() == 1 ? "0" + R : R;
        G = G.length() == 1 ? "0" + G : G;
        B = B.length() == 1 ? "0" + B : B;
        sb.append("#");
        sb.append(A);
        sb.append(R);
        sb.append(G);
        sb.append(B);
        return sb.toString();
    }

from colorpicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.