0

I have seen that there is EffectFactory in Android and it supports Duotone effect. But it only works on API level 14 and up.

The problem is that I need the app to work from API level 11.
So my question is if there is a way to make Duotone image effect on Android below API 14?

With my current code, I access every pixel, get its RGB and change it. But I don't know how duotone works. Here is my code:

public Bitmap doColorFilter(Bitmap src)
{
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
    int A, R, G, B;
    int pixel;

    for (int x = 0; x < width; ++x)
    {
        for (int y = 0; y < height; ++y)
        {
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);

            R = (int) (Color.red(pixel));
            G = (int) (Color.green(pixel));
            B = (int) (Color.blue(pixel));
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}

EDIT:
Sepia toning isn't working like I need it to. Here are three images:
1. original one.
2. one with modified sepia tone effect Der Golem linked
3.the one with duotone effect I need:
original

Sepia effect

Duo tone

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
filipst
  • 1,547
  • 1
  • 30
  • 55
  • Use a ColorMatrix. Here's an example (see the answer with 15 upvotes); http://stackoverflow.com/questions/4141150/convert-bitmap-to-sepia-in-android – Phantômaxx Mar 16 '15 at 08:25
  • I know about ColorMatrix. I am using it for some of the effects. But I can't make Duotone effect. – filipst Mar 16 '15 at 08:54
  • Duotone (toning) is like sepia toning (desaturation + color). Just change the color used for the sepia filter. http://en.wikipedia.org/wiki/Duotone – Phantômaxx Mar 16 '15 at 08:57
  • Not working like I need it. Please see answer below with images. – filipst Mar 16 '15 at 09:18
  • I guess you have to combine 2 differently duotoned pictures to get the effect you are after. – Phantômaxx Mar 16 '15 at 09:26
  • And possibly use a mask (see `PorterDuffXferMode`) to blend them. See this example: http://android-er.blogspot.it/2013/08/merge-images-with-porterduffxfermode.html – Phantômaxx Mar 16 '15 at 09:38

0 Answers0