为灰度图像设置特定颜色

时间:2014-04-05 21:03:03

标签: java android colors color-picker colormatrix

在我的应用程序中,我有一个颜色选择器矩阵,其中包含一组颜色:

enter image description here

和一些灰度图像 - 说天然的褶皱和不同的灰色色调:

enter image description here

颜色是RGB格式,比如说“83334C”。我已经设法通过将整数RGB转换为彩色矩阵滤镜来改变着装的颜色,如:

int red = (color & 0xFF0000) / 0xFFFF;
int green = (color & 0xFF00) / 0xFF;
int blue = color & 0xFF;
float[] colorTransform =
{       
0,0,0,0, red,  // R color
0,0,0,0, green,  // G color
0,0,0,0, blue,  // B color
0,0,0,1, 0
};
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(colorTransform);
ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorTransform); 
BitmapDrawable bd = DollFragment.this.drawableArray[1];
bd.setColorFilter(colorFilter);

但我得到的结果并不是我想要的 - 所有的褶皱和阴影都消失了:

enter image description here

我想看到的结果是:

enter image description here

下面的解决方案似乎不正确,因为我正在更改已经设置了一些RGB值的图像,下面的矩阵只是对图像应用了一些滤镜,而不是设置必要的颜色:

float[] colorTransform =
{       
red/255, 0    , 0    , 0, 0,  // R color
0    , green/255, 0    , 0, 0,  // G color
0    , 0    , blue/255, 0, 0,  // B color
0    , 0    , 0    , 1, 0
};

我已经检查了very useful link和其他一些人,但没有找到我的问题的答案。我确信我必须使用一些数学公式,但不知道哪个。

问题是如何将灰色图像的颜色更改为特定的颜色而不是丢失现有的阴影?

非常感谢您的建议!

0 个答案:

没有答案
相关问题