Here you can find the source of changeHue(Bitmap bmp, int hue, int width, int height)
Parameter | Description |
---|---|
bmp | the bmp |
hue | the hue |
width | the width |
height | the height |
public static Bitmap changeHue(Bitmap bmp, int hue, int width, int height)
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Color; public class Main { /**//w w w. ja v a2s . c o m * Change hue of bitmap. * * @param bmp * the bmp * @param hue * the hue * @param width * the width * @param height * the height * @return the bitmap * @author siddhesh */ public static Bitmap changeHue(Bitmap bmp, int hue, int width, int height) { if (bmp == null) { return null; } // int srcwidth = bmp.getWidth(); // int srcheight = bmp.getHeight(); // create output bitmap // create a mutable empty bitmap Bitmap bitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight()); if ((hue < 0) || (hue > 360)) { return null; } int size = width * height; int[] all_pixels = new int[size]; int top = 0; int left = 0; int offset = 0; int stride = width; bitmap.getPixels(all_pixels, offset, stride, top, left, width, height); int pixel = 0; int alpha = 0; float[] hsv = new float[3]; for (int i = 0; i < size; i++) { pixel = all_pixels[i]; alpha = Color.alpha(pixel); Color.colorToHSV(pixel, hsv); // You could specify target color including Saturation for // more precise results hsv[0] = hue; hsv[1] = 0.2f; all_pixels[i] = Color.HSVToColor(alpha, hsv); } bitmap.setPixels(all_pixels, offset, stride, top, left, width, height); return bitmap; } }