【发布时间】:2013-06-13 23:00:53
【问题描述】:
我有一个 Android 位图,我正在尝试更改图像的 HUE,因为图像是一个红色块,我想通过更改 HUE 将那个块更改为绿色,但我似乎无法在任何地方找到任何代码。
有人知道我该怎么做吗?
画布
【问题讨论】:
-
我正在尝试通过应用色调更改来更改 android 位图,您链接的问题似乎并不相关。
标签: java android colors bitmap hue
我有一个 Android 位图,我正在尝试更改图像的 HUE,因为图像是一个红色块,我想通过更改 HUE 将那个块更改为绿色,但我似乎无法在任何地方找到任何代码。
有人知道我该怎么做吗?
画布
【问题讨论】:
标签: java android colors bitmap hue
如果您将位图包装在 ImageView 中,则有一个非常简单的方法:
ImageView iv = new ImageView(this);
iv.setImageBitmap(yourBitmap);
iv.setColorFilter(Color.RED);
如果您想在屏幕上显示它,您可能希望将其包装在 ImageView 中。
【讨论】:
好吧,如果您只想“将红色变为绿色”,则只需切换 R 和 G 颜色分量即可。原始的,但可以为您完成这项工作。
private Bitmap redToGreen(Bitmap mBitmapIn)
{
Bitmap bitmap = mBitmapIn.copy(mBitmapIn.getConfig(), true);
int []raster = new int[bitmap.getWidth()];
for(int line = 0; line < bitmap.getHeight(); line++) {
bitmap.getPixels(raster, 0, bitmap.getWidth(), 0, line, bitmap.getWidth(), 1);
for (int p = 0; p < bitmap.getWidth(); p++)
raster[p] = Color.rgb(Color.green(raster[p]), Color.red(raster[p]), Color.blue(raster[p]));
bitmap.setPixels(raster, 0, bitmap.getWidth(), 0, line, bitmap.getWidth(), 1);
}
return bitmap;
}
【讨论】:
我相信您不会找到一个简单的“色调”转盘来调整图像的颜色。
使用 ColorMatrix 最接近的近似值(并且应该可以正常工作0)。
This question 及其答案为这个主题提供了很多启示。
这是 ColorMatrix 的technical description:
ColorMatrix is a 5x4 matrix for transforming the color+alpha components of a Bitmap.
The matrix is stored in a single array, and its treated as follows:
[ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t ]
When applied to a color [r, g, b, a], the resulting color is computed as (after clamping)
R' = a*R + b*G + c*B + d*A + e;
G' = f*R + g*G + h*B + i*A + j;
B' = k*R + l*G + m*B + n*A + o;
A' = p*R + q*G + r*B + s*A + t;
【讨论】: