clear Black from Bitmap - Android Graphics

Android examples for Graphics:Bitmap Color

Description

clear Black from Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;

public class Main {
    public static Bitmap clearBlack(Bitmap mBitmap) {

        int picw = mBitmap.getWidth(), pich = mBitmap.getHeight();
        int[] pix = new int[picw * pich];
        mBitmap.getPixels(pix, 0, picw, 0, 0, picw, pich);
        for (int y = 0; y < pich; y++)
            for (int x = 0; x < picw; x++) {
                int index = y * picw + x;
                int r = (pix[index] >> 16) & 0xff;
                int g = (pix[index] >> 8) & 0xff;
                int b = pix[index] & 0xff;

                if (r < 50 && g < 50 && b < 50) {
                    pix[index] = 0x00ffffff;
                }//from   w  ww .  j  a va  2s . c o m
            }

        Bitmap bm = Bitmap.createBitmap(picw, pich, Config.ARGB_4444);
        bm.setPixels(pix, 0, picw, 0, 0, picw, pich);
        return bm;

    }
}

Related Tutorials