1

I'm currently trying to add a color picker to my application which downloads a zip file of images, extracts them and installs them to the user's SystemUI.

I've looked for quite a while to try and find a way to change colors within these icons, but so far I haven't been able to find anything that I could implement.

I'd like to be able to use something like a color mask where it would basically put the color over another color (but not transparent areas) or a color fill would do... I just need to be able to color in the active part of the image and not the inactive part.

Since I'm not allowed to post images yet, here's a direct link to help visualize what I'm trying to achieve.

http://i1135.photobucket.com/albums/m636/Mastur_Mynd/stack_img.png

UPDATE - After messing around a little and looking around some more I've found a bit to help I believe...

package com.masturmods.settings.util;

import net.margaritov.preference.colorpicker.ColorPickerPreference;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;

public class Colorizer extends ColorPickerPreference {

    public Colorizer(Context context) {
        super(context);
    }

    public static void colorize(String pathName, int color) {
        Bitmap dec = BitmapFactory.decodeFile(pathName);
        Bitmap mIcon = dec.copy(Bitmap.Config.ARGB_8888, true);
        Canvas c = new Canvas(mIcon);
        Paint paint = new Paint(color);
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        paint.setColorFilter(f);
        c.drawBitmap(mIcon, 0, 0, paint);
        mIcon.recycle();
    }
}

Thanks to Herry the images pass through to the Canvas now, but they aren't changing at all. I've traced everything so far and the color is being saved by the preference and is being accessed by this code.

Andrew
  • 57
  • 1
  • 10

1 Answers1

0

You need to use this Code in colorize Method

    Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter);

or try this

    Bitmap mIcon = dec.copy(Bitmap.Config.ARGB_8888, true);

Because other method return you Immutable Bitmap.Be care full for Memory i mean you will handle that if arise.For more about Immutable to mutable image Refer this SO link .Click here

Community
  • 1
  • 1
Herry
  • 7,037
  • 7
  • 50
  • 80
  • Thanks! That got the Canvas to take the mIcon Bitmap, however nothing is happening to the images. Any ideas on that part? – Andrew Apr 20 '12 at 10:29
  • Are you looking to some thing like this in this SO Question.http://stackoverflow.com/questions/4354939/understanding-the-use-of-colormatrix-and-colormatrixcolorfilter-to-modify-a-draw – Herry Apr 20 '12 at 10:36
  • Is there a way to implement this while ignoring the grayscale? ignoring something if its saturation is low enough? – Andrew Apr 20 '12 at 11:30
  • Also this method seems to be inapplicable to a Bitmap... Not sure how to implement this? – Andrew Apr 20 '12 at 11:47
  • Have check this Code http://xjaphx.wordpress.com/2011/10/18/image-processing-tint-color-yet-another/ when i apply this Code to your http://i1135.photobucket.com/albums/m636/Mastur_Mynd/stack_img.png i can see that Light Blue Color is Replaced with some thing like Pink. – Herry Apr 20 '12 at 12:40