get Highlight Color From Bitmap - Android Graphics

Android examples for Graphics:Bitmap Color

Description

get Highlight Color From Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.Color;

public class Main {
    public static int getHighlightColorFromBitmap(final Bitmap bitmap) {
        int incolor = Color.BLACK;
        if (null != bitmap) {
            final Bitmap bitmap1px = Bitmap.createScaledBitmap(bitmap, 1,
                    1, false);/*ww  w .  j av a2  s  . c om*/
            incolor = bitmap1px.getPixel(0, 0);
        }
        return getHighlightColor(incolor);
    }

    public static int getHighlightColor(int sampleColor) {
        // Set a constant value level in HSV, in case the averaged color is too light or too dark.
        float[] hsvBackground = new float[3];
        Color.colorToHSV(sampleColor, hsvBackground);
        hsvBackground[2] = 0.3f; // value parameter

        return Color.HSVToColor(0xf2, hsvBackground);
    }
}

Related Tutorials