混色的android [英] Color mixing in android

查看:194
本文介绍了混色的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的工作中,我有五种颜色:红,绿,蓝,黄,紫色

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.

用户触摸任何颜色按钮这个颜色搭配与previously绘制的颜色。

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

我没有任何线索如何添加两种颜色codeS,并得到第三种颜色。

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

编辑:

我也必须设置该颜色的ImageView位图

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

如何设置呢?

推荐答案

这是另一种答案:

您可以混合在hexs位:

You can mix the bits in the hexs:

public static int mixTwoColors( int color1, int color2, float amount )
{
    final byte ALPHA_CHANNEL = 24;
    final byte RED_CHANNEL   = 16;
    final byte GREEN_CHANNEL =  8;
    final byte BLUE_CHANNEL  =  0;

    final float inverseAmount = 1.0f - amount;

    int a = ((int)(((float)(color1 >> ALPHA_CHANNEL & 0xff )*amount) +
                   ((float)(color2 >> ALPHA_CHANNEL & 0xff )*inverseAmount))) & 0xff;
    int r = ((int)(((float)(color1 >> RED_CHANNEL & 0xff )*amount) +
                   ((float)(color2 >> RED_CHANNEL & 0xff )*inverseAmount))) & 0xff;
    int g = ((int)(((float)(color1 >> GREEN_CHANNEL & 0xff )*amount) +
                   ((float)(color2 >> GREEN_CHANNEL & 0xff )*inverseAmount))) & 0xff;
    int b = ((int)(((float)(color1 & 0xff )*amount) +
                   ((float)(color2 & 0xff )*inverseAmount))) & 0xff;

    return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
}

这篇关于混色的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆