Search code examples
androidcanvasbitmapcolorfilter

How to apply gradient color filter, or delete half of a bitmap


Okay, I'm starting with this drawable: https://dl.dropboxusercontent.com/u/43058382/property.png

I need it to look like this: https://dl.dropboxusercontent.com/u/43058382/property_2.png

private Bitmap createIconMapMarker(Drawable bottom, Drawable top, int color, boolean black_white, boolean split_property) {
    Bitmap marker;

if (black_white) {
        // if true I make image black and white.
    } else {
        if (split_property) {
            // if this is true, I need a marker that is half one color, half another
            // for now I'm just setting each one to that color

            PorterDuff.Mode mode = PorterDuff.Mode.MULTIPLY;
            bottom.setColorFilter(michael, mode);
            top.setColorFilter(franklin, mode);
        } else {
            // if it's not true, I only need to color the bottom layer

            PorterDuff.Mode mode = PorterDuff.Mode.MULTIPLY;
            bottom.setColorFilter(color, mode);
        }
    }

    marker = Bitmap.createBitmap(bottom.getIntrinsicWidth(),
            bottom.getIntrinsicHeight(), Config.ARGB_8888);

    Canvas canvas = new Canvas(marker);

    if (split_property) {
        //need code here
        // possibly just remove half the pixels from one layer
        // possibly apply some sort of linear gradient filter
    } else {
        bottom.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        top.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        bottom.draw(canvas);
        top.draw(canvas);
    }

Solution

  • I just ended up creating another resource file with only half the image. Now I color them seperately and all is well.