0
void changeColor(int a, int r, int g, int b){
    String hex = + Integer.toHexString(a) + Integer.toHexString(r) +
                   Integer.toHexString(g) + Integer.toHexString(b);

    int color = hex //Obviously this is a type mismatch, but how do I do this?

    mpaint.setColor(color);
}

Obviously this is a type mismatch, but how do I do this?

1

1 Answer 1

1

If you need a Color variable, you can use the Color contructor (but have to change the range to 0.0-1.0)

Color(float r, float g, float b, float a)

But if you need an int in the end, you have to use bitshifts (this is an example, you have to know how the color components need to be ordered) :

int color = (r << 24) | (g << 16) | (b << 8) | a;

Sign up to request clarification or add additional context in comments.

1 Comment

Actually I found out that the Android SDK for the paint object has a built in color setter in the same format. mpaint.setARGB(a, r, g, b);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.