Skip to content
Advertisement

Convert RGB to HSV in android

I want to get the ARGB values from a pixel and convert to HSV and then set the pixel with the new values.

I don’t fully understand how to do that. Can anyone help me?

Advertisement

Answer

Let’s say you have a Bitmap object and x and y co-ordinates. You can get the color from the bitmap as a 32-bit value like this:

JavaScript

You can separate out the argb components like this:

JavaScript

Then you can convert to HSV like this:

JavaScript

Now you can manipulate the HSV values however you want. When you are done you can convert back to rgb:

JavaScript

or like this is you want to use the alpha value:

JavaScript

Then you can write the color back to the bitmap (it has to be a mutable Bitmap):

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement