我希望以编程方式更改背景图像 (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/