Convert Rgb Color To Hex Color
I am taking a color from an ImageView using OnTouchListener. Red, Green, Blue color code can be successfully obtained, but i cant convert RGB to HEX .. example : my rgb values are
Solution 1:
Answer :
Just use:
String hex = String.format("#%02x%02x%02x", redValue, greenValue, blueValue);
This will convert all the Red, Green and Blue values to Hex String.
Hope it helps.
Solution 2:
Use Integer.toHexString(color); to convert an integer to hex string.
Example:
int color = 0xff334433;
String hex = Integer.toHexString(color);
System.out.println(hex); // this prints - ff334433
Solution 3:
You are sending wrong the parameters to the function String.format to get the hexColor.
Try this one:
String hexColor = String.format("#%06X", redValued, greenValue, blueValue);
Post a Comment for "Convert Rgb Color To Hex Color"