Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color mixing in android

Tags:

I am working on application in which i have five colors:Red,Green,Blue,Yellow,purple

I want to implement color mixing from those colors:such that like there are five button for each color.

User touch whichever color button this color mix with previously drawn color.

I have not any clue how to add two color codes and get third color.

EDitED:

I have to also set this color to imageview's bitmap

how can i set this?

like image 455
chikka.anddev Avatar asked May 20 '11 09:05

chikka.anddev


People also ask

Is there an app where you can mix colors?

Paleto is able to extract the colors you like from your photos and the tinting function that mixes colors to create new ones. It also provides a library of 1400 colors and a palette that lets you store and share your colors.

What is visual color mixing?

Optical color mixing is a phenomenon that happens when a viewer perceives color in an image as a result of two or more colors that are positioned next to, or near each other. The perceived color is not actually on the surface.


2 Answers

Since April 2015 you can use blendARGB method from v4 support library:

int resultColor = ColorUtils.blendARGB(color1, color2, 0.5F);

Ratio value has to be 0.5 to achive even mix.

like image 181
Szymon Grochowiak Avatar answered Sep 21 '22 02:09

Szymon Grochowiak


SlidingTabStrip has really useful method for blending colors, looks great when used with ViewPager:

private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
}
like image 41
Marqs Avatar answered Sep 19 '22 02:09

Marqs