Enhancing ImageView brightness programmatically

前端 未结 5 1951
不知归路
不知归路 2021-01-03 10:56

I have an android app in which I am increasing brightness of image with the code below. But this is very slow so does anyone knows a fast way to enhance image brightness of

5条回答
  •  别那么骄傲
    2021-01-03 11:26

    I can't exactly remember where i got this from but i use this (with negative value to get something darker, put some positive value to get something bright)

    drawable.setColorFilter(applyLightness(-30));
    
    
    public static PorterDuffColorFilter applyLightness(int progress)
    {
        if (progress > 0)
        {
            int value = (int) progress * 255 / 100;
            return new PorterDuffColorFilter(Color.argb(value, 255, 255, 255), Mode.SRC_OVER);
        }
        else
        {
            int value = (int) (progress * -1) * 255 / 100;
            return new PorterDuffColorFilter(Color.argb(value, 0, 0, 0), Mode.SRC_ATOP);
        }
    }
    

    edit : found where i took this from : Adjusting Lightness using ColorMatrix

提交回复
热议问题