1

我有一个 Android 位图,我正在尝试更改图像的 HUE,因为图像是一个红色块,我想通过更改 HUE 将该块更改为绿色,但我似乎找不到任何代码在任何地方。

有谁知道我该怎么做?

帆布

4

3 回答 3

2

如果你用ImageView一个非常简单的方法包装你的位图:

ImageView iv = new ImageView(this);
iv.setImageBitmap(yourBitmap);
iv.setColorFilter(Color.RED);

ImageView如果你想在屏幕上显示它,你可能想把它包装起来。

于 2020-06-17T19:12:32.227 回答
1

好吧,如果您所追求的只是“将红色变为绿色”,则只需切换 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;
}
于 2015-08-15T04:38:49.330 回答
0

我相信您不会找到一个简单的“色调”表盘来调整图像的颜色。

最接近的近似值(并且应该可以正常工作0)是使用 ColorMatrix。

这个问题及其答案为这个主题提供了很多启示。

以下是ColorMatrix的技术描述:

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; 
于 2013-06-14T03:08:44.753 回答