簡體   English   中英

你能在android ImageView上更改位圖的圖像色調嗎?

[英]Can you change image hue of bitmap on android ImageView?

這是情況,我有一個SeekBar,當我滑動它時,我想要改變ImageView中圖像的色調。 我所看到的關於改變色調的所有事情都需要使用ColorMatrix,但我不知道如何將位圖與顏色矩陣相關聯。 建議?

    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);

這里有一個以灰度繪制位圖的示例。

http://www.mail-archive.com/android-developers@googlegroups.com/msg38890.html

只需替換cm.setSaturation(0); cm.setRotate(int axis, float degrees);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM