Reputation: 3695
I successfully implemented functionality to adjust the contrast and/or brightness of an ImageView via values coming from user's SeekBars selections. For the contrast it looks like that (similar for brightness):
// Contrast
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(new float[] {
scale, 0, 0, 0, translate, // Red
0, scale, 0, 0, translate, // Green
0, 0, scale, 0, translate, // Blue
0, 0, 0, 1, 0 }); // Alpha
imageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix);
So I could adjust the contrast and/or brightness just by scaling (multiplication) or translating (addition) the RGB values with another value.
How can I do the same thing (using a matrix) for adjusting the image's color temperature?
Upvotes: 2
Views: 2687
Reputation:
I followed destiny answer, but had to do some adjustment, here is how i did it:
let amount = 255;
let value = 0;
(1.0000* amount)/255.0, 0, 0, 0, 0,
0, ((1.0000+value)* amount)/255.0, 0, 0, 0,
0, 0, ((1.0000+value)* amount)/255.0, 0, 0,
0, 0, 0, 1, 0
Upvotes: 0
Reputation: 510
I just created such a Matrix for my application to adjust the color temperature.
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(new float[] {
RED/255.0f, 0, 0, 0, 0,
0, GREEN/255.0f, 0, 0, 0
0, 0, BLUE/255.0f, 0, 0,
0, 0, 0, 1, 0});
imageView.setColorFilter(new ColorMatrixColorFilter(colorMatrix);
The values for RED, GREEN and BLUE you can get for example from here: http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
It works perfectly fine and even images with a very strong color temperature can be adjusted accordingly :)
Upvotes: 3