Android Bitmap Color Change createSaturatedBitmap(final Bitmap bitmap)

Here you can find the source of createSaturatedBitmap(final Bitmap bitmap)

Description

Used to remove the saturation (if saturate) and slightly enlarge a Bitmap .

License

Apache License

Parameter

Parameter Description
bitmap The Bitmap to filer.

Declaration

public static final Bitmap createSaturatedBitmap(final Bitmap bitmap) 

Method Source Code

//package com.java2s;
/*//  w w w  .  j  a v a  2 s  .c om
 * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

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

public class Main {
    /**
     * Used to remove the saturation (if saturate) and slightly enlarge a
     * {@link Bitmap}.
     * 
     * @param bitmap The {@link Bitmap} to filer.
     */
    public static final Bitmap createSaturatedBitmap(final Bitmap bitmap) {
        if (bitmap == null) {
            return null;
        }

        final Bitmap mBitmap = Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Bitmap.Config.RGB_565);
        final Canvas mCanvas = new Canvas(mBitmap);
        final Paint mPaint = new Paint();
        final ColorMatrix mColorMatrix = new ColorMatrix();
        mColorMatrix.setSaturation(0);
        final ColorMatrix mDarkMatrix = new ColorMatrix();
        mDarkMatrix.setScale(0.3f, 0.3f, 0.3f, 1.0f);
        mColorMatrix.postConcat(mDarkMatrix);
        final ColorMatrixColorFilter mFilter = new ColorMatrixColorFilter(
                mColorMatrix);
        mPaint.setColorFilter(mFilter);
        mCanvas.drawBitmap(bitmap, 0, 0, mPaint);
        return mBitmap;
    }
}

Related

  1. adjustedContrast(Bitmap src, double value)
  2. boost(Bitmap src)
  3. brightness(Bitmap src, int value)
  4. changeHue(Bitmap bmp, int hue, int width, int height)
  5. createAnaglyphBitmap(Bitmap bitmap)
  6. dilate(Bitmap bitmap, int[][] se)
  7. dilate(Bitmap source, Bitmap target, int[][] se)
  8. doBrightness(Bitmap src, int value)
  9. erosion(Bitmap bitmap, int[][] se)