Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use the LightingColorFilter to make the image form dark to light

I want to add light of the image, I want to use LightingColorFilter

LightingColorFilter lcf = new LightingColorFilter( mul, add); 
imageView.setColorFilter(lcf);

but I don't know how to adjust mul, add, can you give some link or code or parameters to adjust the light of the image?

Thank you

like image 662
pengwang Avatar asked Aug 13 '11 06:08

pengwang


People also ask

How do you change the color of a drawable?

To change the background color programatically, try to get the shape drawable and then use SetTint to change the color value.

What is color filter Android?

The documentation for the base abstract class stipulates that “a color filter can be used with a Paint to modify the color of each pixel drawn with that paint”. This is a powerful tool that can be used for: Applying effects and adjustments to images. Tinting of icons and logos.


2 Answers

The integer values are colours (you may want to have a closer look here http://developer.android.com/reference/android/graphics/Color.html)
4 Bytes are used, one for alpha, one for red, one for green, one for blue range - every single from 0 to 255 (hex 0 to FF)

so the colour in hex looks like

0 x 00     00   00    00
    alpha  red  green blue

If you want to set for example red to zero, use

mul: 0xFF00FFFF
add: 0x00000000

If you want to force blue to be full-on, use

mul: 0xFFFFFFFF
add: 0x000000FF 
like image 177
DonGru Avatar answered Sep 18 '22 14:09

DonGru


Canvas canvas= new Canvas(my_bitmap); // create canvas from bitmap
Paint my_paint = new Paint(); // create Paint from bitmap

my_paint.setColorFilter(new LightingColorFilter(0x77777777, 0x77777777));//(mul, add)

canvas.drawBitmap(my_bitmap, 0, 0, my_paint );

1- now you can show my_bitmap

2- now my_bitmap have about 50% more light

3- you can change (mul, add) to understand how work

4- also can use my_paint in other graphic method

like image 39
mahdi hosseini Avatar answered Sep 19 '22 14:09

mahdi hosseini