Here you can find the source of createSaturatedBitmap(final Bitmap bitmap)
Parameter | Description |
---|---|
bitmap | The Bitmap to filer. |
public static final Bitmap createSaturatedBitmap(final Bitmap bitmap)
//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; } }