Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (c) 2016, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.car.overview.utils;
     17 
     18 import android.graphics.Bitmap;
     19 import android.graphics.Canvas;
     20 import android.graphics.ColorMatrix;
     21 import android.graphics.ColorMatrixColorFilter;
     22 import android.graphics.Paint;
     23 
     24 /**
     25  * Utility functions used by the Stream Service.
     26  */
     27 public class BitmapUtils {
     28     /**
     29      * Apply saturation to a bitmap
     30      */
     31     public static Bitmap applySaturation(Bitmap bitmap, float saturation) {
     32         Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
     33         Canvas canvas = new Canvas(mutableBitmap);
     34 
     35         Paint paint = new Paint();
     36         ColorMatrix colorMatrix = new ColorMatrix();
     37         colorMatrix.setSaturation(saturation);
     38         ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);
     39         paint.setColorFilter(filter);
     40         canvas.drawBitmap(bitmap, 0, 0, paint);
     41         return mutableBitmap;
     42     }
     43 }
     44