Java – how to lighten or darken bitmaps

For example, how do I get an existing bitmap

Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.somebitmap);

And write a method to return the dark version of the bitmap?

private Bitmap darkenBitMap(Bitmap bm) { }

So far, I've been trying to use paint and canvas, but there's no result

Solution

I finally understand I hope it can help others

private Bitmap darkenBitMap(Bitmap bm) {

    Canvas canvas = new Canvas(bm);
    Paint p = new Paint(Color.RED);
    //ColorFilter filter = new LightingColorFilter(0xFFFFFFFF,0x00222222); // lighten
    ColorFilter filter = new LightingColorFilter(0xFF7F7F7F,0x00000000);    // darken
    p.setColorFilter(filter);
    canvas.drawBitmap(bm,new Matrix(),p);

    return bm;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>