Android:如何改变图像的色调?

标签 android

我希望以编程方式更改背景图像 (PNG) 的色调。如何在 Android 上完成此操作?

最佳答案

我测试了接受的答案,不幸的是它返回了错误的结果。我从 here 找到并修改了这段代码效果很好:

// hue-range: [0, 360] -> Default = 0
public static Bitmap hue(Bitmap bitmap, float hue) {
    Bitmap newBitmap = bitmap.copy(bitmap.getConfig(), true);
    final int width = newBitmap.getWidth();
    final int height = newBitmap.getHeight();
    float [] hsv = new float[3];

    for(int y = 0; y < height; y++){
        for(int x = 0; x < width; x++){
            int pixel = newBitmap.getPixel(x,y);
            Color.colorToHSV(pixel,hsv);
            hsv[0] = hue;
            newBitmap.setPixel(x,y,Color.HSVToColor(Color.alpha(pixel),hsv));
        }
    }

    bitmap.recycle();
    bitmap = null;

    return newBitmap;
}

关于Android:如何改变图像的色调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10254630/

相关文章:

android - 为 Gradle 设置 Deckard。 Robolectric 测试错误

android - SQLITE with Android(设置数据库的最佳方法)

java - 自定义控件中的android数据绑定(bind)

android - Android开发设备id的用途是什么?

android - 改造 - 是否可以避免从应用程序拦截器调用实际 api 并返回硬编码响应?

android - 填充 TextView 列表时动态设置 contentDescription

android - 膨胀类 android.support.v7.widget.RecyclerView(Eclipse) 时出错

android - 适用于 Android 或 iPhone 的 Cyber​​Tracker 应用程序

android - Flutter 的可重用组件

android - 如何使用node-rsa加密node.js中的数据并在android中解密加密的数据?