Reputation: 11782
I am using this code to randomly change the color of my textView. I have a black background so sometimes these colors are hard to read.
int r = (rand.nextInt(176) * 80 ) / 256;
int g = (rand.nextInt(176) * 80 ) / 256;
int b = (rand.nextInt(176) * 80 ) / 256;
TextView pos = (TextView) view.findViewById(R.id.position);
pos.setText(((Integer)(position + 1)).toString());
pos.setTextSize(30);
pos.setTextColor(Color.argb(255,r,g,b));
TextView data = (TextView) view.findViewById(R.id.textOfTip);
data.setText(tipsList[position].toString());
data.setTextSize(24);
data.setTextColor(Color.argb(255,r,g,b));
My question is, how can i increase the brightness or luminous effect of the text color so they can read easily.
Best Regards
Upvotes: 0
Views: 188
Reputation: 67522
First, get your color in the format 0xAARRGGBB
(example, solid red is 0xFFFF0000). Then, push it to the method colorToHSV
. Next, change the L/V/B value (which vary slightly, but I think will be close enough for what you're doing). Lastly, call HSVToColor
to get your new color in 0xAARRGGBB
format again. There are then several ways to convert this to R,G,B values, which usually involve byte shifting.
Something like this:
int color = 0xFFFF0000;
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] = 0.2f;
color = Color.HSVToColor(hsv);
int[] rgb = new int[3];
MyColor.colorToRGB(color, rgb); // Your custom method
// The rgb array now contains your RGB colors.
Note: There is also RGBToHSV
, which may come in handy.
Upvotes: 2
Reputation: 9914
I think there are some formulae for acheiving the brightness and luminous effct.This article gives you good understanding about it.
Formula to determine brightness of RGB color
Upvotes: 0