Android Bitmap Color Change makeSaturated(Bitmap source, int level)

Here you can find the source of makeSaturated(Bitmap source, int level)

Description

Make colors of bitmap saturated.

Parameter

Parameter Description
source the source
level the level

Return

the bitmap

Declaration

public static Bitmap makeSaturated(Bitmap source, int level) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Color;

public class Main {
    /**/*from  ww  w. ja  v  a2  s  .  c  om*/
     * Make colors of bitmap saturated.
     * 
     * @param source
     *            the source
     * @param level
     *            the level
     * @return the bitmap
     * @author siddhesh
     */
    public static Bitmap makeSaturated(Bitmap source, int level) {
        // get image size
        int width = source.getWidth();
        int height = source.getHeight();
        int[] pixels = new int[width * height];
        float[] HSV = new float[3];
        // get pixel array from source
        source.getPixels(pixels, 0, width, 0, 0, width, height);

        int index = 0;
        // iteration through pixels
        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                // get current index in 2D-matrix
                index = y * width + x;
                // convert to HSV
                Color.colorToHSV(pixels[index], HSV);
                // increase Saturation level
                HSV[1] *= level;
                HSV[1] = (float) Math.max(0.0, Math.min(HSV[1], 1.0));
                // take color back
                pixels[index] |= Color.HSVToColor(HSV);
            }
        }
        // output bitmap
        Bitmap bmOut = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
        return bmOut;
    }
}

Related

  1. erosion(Bitmap bitmap, int[][] se)
  2. getGrayscaleHistogram(Bitmap bm)
  3. increaseGreen(Bitmap src, int value)
  4. initAlphaChannel( BitmapFactory.Options bitmapOptions)
  5. initBitmapFactoryOptions( BitmapFactory.Options bitmapOptions, int maxWidth, int maxHeight)
  6. makeVivid(Bitmap src, int type, float percent)
  7. setAlpha(Bitmap sourceImg, int number)
  8. setAlpha(Bitmap sourceImg, int number)
  9. tiltShift(Bitmap sentBitmap, int radius, int x, int y)