update Bitmap Color - Android Graphics

Android examples for Graphics:Bitmap Color

Description

update Bitmap Color

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;

import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;

public class Main {
    public static Bitmap updateBitmapColor(Bitmap bitmap, int r, int g,
            int b) {
        if (bitmap != null) {
            Bitmap tmp = bitmap.copy(Config.ARGB_8888, true);
            Canvas c = new Canvas(tmp);
            Paint mPaint = new Paint();
            mPaint.setAntiAlias(true);/*from w w  w. j  a v  a2  s .  co  m*/
            float[] f = { 0f, 0f, 0f, 0f, r, 0f, 0f, 0f, 0f, g, 0f, 0f, 0f,
                    0f, b, 0f, 0f, 0f, 1f, 0f };
            ColorMatrix cm = new ColorMatrix(f);
            mPaint.setColorFilter(new ColorMatrixColorFilter(cm));
            c.drawBitmap(tmp, 0, 0, mPaint);
            return tmp;
        }
        return null;
    }
}

Related Tutorials