1

I am using the following method to change the hue of a bitmap:

public Bitmap changeHue( Bitmap source, double hue ) {

    Bitmap result = Bitmap.createBitmap( screenWidth, screenHeight, source.getConfig() );

    float[] hsv = new float[3];
    for( int x = 0; x < source.getWidth(); x++ ) {
        for( int y = 0; y < source.getHeight(); y++ ) {
            int c = source.getPixel( x, y );
            Color.colorToHSV( c, hsv );
            hsv[0] = (float) ((hsv[0] + 360 * hue) % 360);
            c = (Color.HSVToColor( hsv ) & 0x00ffffff) | (c & 0xff000000);
            result.setPixel( x, y, c );
        }
    }

    return result;
}

It works perfectly and maintains the luminance of the bitmap. However this method is very slow when changing the hue of a bitmap size 800*480 or higher. How can I optimize it without losing too much image quality?

Tim
  • 14,999
  • 1
  • 45
  • 68
Mikko P.
  • 41
  • 1
  • 8
  • You will probably have to use OpenGL to exploit the GPU. – Gene Jun 13 '12 at 00:46
  • As addendum to @Gene's answer: for newer devices (>= HoneyComb) you can use RenderScript to significantly speed up image manipulation. There's pretty decent [blog post on developer.android.com](http://android-developers.blogspot.co.nz/2012/01/levels-in-renderscript.html) on this topic. – MH. Jun 13 '12 at 03:30

1 Answers1

0

If you wrap your Bitmap in an ImageView there is a very simple way:

ImageView circle = new ImageView(this);
circle.setImageBitmap(yourBitmap);
circle.setColorFilter(Color.RED);
xjcl
  • 12,848
  • 6
  • 67
  • 89