How to change orange color to green in bitmap using ColorMatrixFilter

1k Views Asked by At

How to use the colorMatirxFilter to change orange color to green on a bitmap. Code samples would help. Please add explanation for the ColorMatrixFilter matrix.

I want to change the theme color based on user's selection.

1

There are 1 best solutions below

0
On

As we know orange is not a pure color as Red, Green or Blue. This means that orange has three components, R,G and B components. Therefore, please try this:
1) Convert the orange (three values) to gray (one value) by using
Gray = 0.3*RED + 0.59*GREEN+0.11*Blue;

2) Then, using ColorMatrixFilter (see Torious's link) set pixel values of those pixels which you want to change as:

Set ZERO (0 values) to Red and Blue components (as pixel values). Set the Gray value (we just calculated) to Green component (as pixel value).

Then, you get your result.