现在的情况是,我有一个seekbar,当我滑动它时,我想改变图像视图中图像的色调。我看到的所有关于改变色调的事情都需要使用颜色矩阵,但我不知道如何将位图与颜色矩阵相关联。建议?
最佳答案
public static void adjustHue(ColorMatrix cm, float value)
{
value = cleanValue(value, 180f) / 180f * (float) Math.PI;
if (value == 0)
{
return;
}
float cosVal = (float) Math.cos(value);
float sinVal = (float) Math.sin(value);
float lumR = 0.213f;
float lumG = 0.715f;
float lumB = 0.072f;
float[] mat = new float[]
{
lumR + cosVal * (1 - lumR) + sinVal * (-lumR), lumG + cosVal * (-lumG) + sinVal * (-lumG), lumB + cosVal * (-lumB) + sinVal * (1 - lumB), 0, 0,
lumR + cosVal * (-lumR) + sinVal * (0.143f), lumG + cosVal * (1 - lumG) + sinVal * (0.140f), lumB + cosVal * (-lumB) + sinVal * (-0.283f), 0, 0,
lumR + cosVal * (-lumR) + sinVal * (-(1 - lumR)), lumG + cosVal * (-lumG) + sinVal * (lumG), lumB + cosVal * (1 - lumB) + sinVal * (lumB), 0, 0,
0f, 0f, 0f, 1f, 0f,
0f, 0f, 0f, 0f, 1f };
cm.postConcat(new ColorMatrix(mat));
}
private static float cleanValue(float p_val, float p_limit)
{
return Math.min(p_limit, Math.max(-p_limit, p_val));
}
-------
while drawing from canvas ... create an object of paint and ... set...
ColorMatrix mat = new ColorMatrix();`
adjustHue(mat, 110);
paint.setColorFilter(new ColorMatrixColorFilter(mat));
----
canvas.draw(bmp, 0,0,paint);
关于android - 你能在android ImageView上更改位图的图像色调吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9401733/