GOLDEE
GOLDEE

Reputation: 2318

How to Convert #RGBto #RRGGBB

I have to convert a color string in the format #RGB to #RRGGBB like #0af To #RRGGBB now can any one help out here using android

Upvotes: 1

Views: 2135

Answers (3)

Daryn
Daryn

Reputation: 768

One way is:

String rgb = "#0AF";
String rrggbb = "#";
for (int i = 1; i < rgb.length(); i++) {
    rrggbb += (rgb.charAt(i) + "" + rgb.charAt(i));
}

Upvotes: 3

GOLDEE
GOLDEE

Reputation: 2318

String hexColor = String.format("#%06X", (0xFFFFFF & intColor));

thats what i was searching. It will ensure that color string always will be #RRGGBB.

Upvotes: 0

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186668

int newRgb = 17 * (((oldRgb & 0xF00) << 8) | ((oldRgb & 0xF0) << 4) | (oldRgb & 0xF));

Upvotes: 2

Related Questions