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?

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
charles horvath
  • 315
  • 1
  • 2
  • 9
  • possible duplicate of [Convert a string representation of a hex dump to a byte array using Java?](http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java) – Bozho Jan 03 '12 at 22:54

1 Answers1

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;

fury
  • 597
  • 1
  • 4
  • 15
  • 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); – charles horvath Jan 04 '12 at 00:34