• Advertisement
Sign in to follow this  

Android Bitmap change Hue

This topic is 1681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have got a Android bitmap and i'm trying to change the HUE of the image, as the image is a red block, I want to change that block to green by just changing the HUE, but I can't seem to find any code anywhere.

Anyone know how I can do this?


Share this post

Link to post
Share on other sites

Hi, I couldn't find it anywhere. And I was kind of bored, so I thought why couldn't I help you? smile.png So I wrote simple function which does all the job for you. 

Please note that this function will not work at real time, well MAYBE it would work if the bitmap would be very small, and your phone super fast. If you would like to do this in real time, then I think you should look into OpenGL. But don't take my word for it, because I didn't use Canvas for android in a LONG time, maybe you can change it in real time.


Here it is:

     * @param bitmap which bitmap to convert
     * @param hue any value from 0 to 360.
     * @return bitmap with new hue values
    public Bitmap setHue(Bitmap bitmap, float hue){
        Bitmap newBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
        int width = newBitmap.getWidth();
        int height = newBitmap.getHeight();
        float [] hvs = new float[3];

        for(int y = 0; y < height; y++){
            for(int x = 0; x < width; x++){
                int pixel = newBitmap.getPixel(x,y);
                hvs[0] = hue;
        return newBitmap;

Here are the hue values:



Just pass your bitmap, and any value from 0 to 360 in this function, and it will return new, processed bitmap.



Edited by Edvinas Kilbauskas

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement