Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualEdvinas Kilbauskas

Posted 14 June 2013 - 04:54 AM

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);
                Color.colorToHSV(pixel,hvs);
                hvs[0] = hue;
                newBitmap.setPixel(x,y,Color.HSVToColor(Color.alpha(pixel),hvs));
            }
        }
        return newBitmap;
    }

Here are the hue values:

360px-HueScale.svg.png

 

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

 

 


#1Edvinas Kilbauskas

Posted 14 June 2013 - 04:50 AM

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

Please note that this function will not work at real time, you would need to change the hue before you use it. If you would like to do this in real time, I think you could only do this in OpenGL. But don't take my word for it, because I didn't use Canvas for android in a LONG 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);
                Color.colorToHSV(pixel,hvs);
                hvs[0] = hue;
                newBitmap.setPixel(x,y,Color.HSVToColor(Color.alpha(pixel),hvs));
            }
        }
        return newBitmap;
    }

Here are the hue values:

360px-HueScale.svg.png

 

 


PARTNERS