Android Utililty Methods Bitmap Color Change

List of utility methods to do Bitmap Color Change

Description

The list of methods to do Bitmap Color Change are organized into topic(s).

Method

int[]getGrayscaleHistogram(Bitmap bm)
get Grayscale Histogram
int[] histogram = new int[256];
int ptr = 0;
while (ptr < histogram.length)
    histogram[ptr++] = 0;
int hlen = bm.getWidth(), vlen = bm.getHeight();
int pixel;
for (int y = 0; y < vlen; y++) {
    for (int x = 0; x < hlen; x++) {
...
BitmapincreaseGreen(Bitmap src, int value)
Increase green.
int width = src.getWidth();
int height = src.getHeight();
final float factor = 1.1f;
Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
int[] pix = new int[width * height];
src.getPixels(pix, 0, width, 0, 0, width, height);
int A, R, G, B;
int i = 0;
...
booleaninitAlphaChannel( BitmapFactory.Options bitmapOptions)
set bitmap options preferred config
if (!TextUtils.isEmpty(bitmapOptions.outMimeType)) {
    if (mayNotHasAlphaChannel(bitmapOptions)) {
        bitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
        bitmapOptions.inDither = false;
    } else {
        bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
    return true;
...
booleaninitBitmapFactoryOptions( BitmapFactory.Options bitmapOptions, int maxWidth, int maxHeight)
init Bitmap Factory Options
if (bitmapOptions.inJustDecodeBounds && bitmapOptions.outHeight > 0
        && bitmapOptions.outWidth > 0) {
    if (bitmapOptions.outWidth > (maxWidth << 1)
            || bitmapOptions.outHeight > (maxHeight << 1)) {
        bitmapOptions.inSampleSize = Math.max(
                bitmapOptions.outWidth / maxWidth,
                bitmapOptions.outHeight / maxHeight);
    bitmapOptions.inJustDecodeBounds = false;
    return true;
return false;
BitmapmakeSaturated(Bitmap source, int level)
Make colors of bitmap saturated.
int width = source.getWidth();
int height = source.getHeight();
int[] pixels = new int[width * height];
float[] HSV = new float[3];
source.getPixels(pixels, 0, width, 0, 0, width, height);
int index = 0;
for (int y = 0; y < height; ++y) {
    for (int x = 0; x < width; ++x) {
...
BitmapmakeVivid(Bitmap src, int type, float percent)
Make colors in bitmap vivid.
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);
...
BitmapsetAlpha(Bitmap sourceImg, int number)
set Alpha
int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];
sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0,
        sourceImg.getWidth(), sourceImg.getHeight());
number = number * 255 / 100;
for (int i = 0; i < argb.length; i++) {
    argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF);
sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(),
...
BitmapsetAlpha(Bitmap sourceImg, int number)
set Alpha
int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];
sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0,
        sourceImg.getWidth(), sourceImg.getHeight());
number = number * 255 / 100;
for (int i = 0; i < argb.length; i++) {
    argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF);
sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(),
...
BitmaptiltShift(Bitmap sentBitmap, int radius, int x, int y)
Tilt shift effect on bitmap.
Bitmap bmp = sentBitmap.copy(sentBitmap.getConfig(), true);
int w = sentBitmap.getWidth();
int h = sentBitmap.getHeight();
int[] pix = new int[w * h];
bmp.getPixels(pix, 0, w, 0, 0, w, h);
int radiusSquared = 110 * 110;
for (int r = radius; r > 1; r /= 2) {
    for (int i = r; i < h - r; i++) {
...
BitmapchangeBitmapColor(Bitmap bmp, int color)
change Bitmap Color
Bitmap result = Bitmap.createBitmap(bmp.getWidth(),
        bmp.getHeight(), bmp.getConfig());
Canvas c = new Canvas(result);
Paint paint = new Paint();
ColorFilter filter = new LightingColorFilter(color, 1);
paint.setColorFilter(filter);
c.drawBitmap(bmp, 0, 0, paint);
return result;
...