Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Color.rgb do in Android?

I'm making an app that does some real time image processing using the camera. I've written code in Java and now I'm trying to port that code over to native code to speed things up. An essential part of the Java code is to use the Color.rgb (from the android.Graphics library) method to convert my array of pixel intensities into "color-ints" (description given by the documentation). The specific line of code is:

Color.rgb(pixel, pixel, pixel)

where pixel is an integer between 0 and 255. I then use the drawBitmap method to draw this array of color-ints to a canvas. Yes I realise that this results in a B&W image because that is what I need.

Now I need to convert the pixel intensities into color-ints in my C code, and I can't use the above method as there is no library in C. I'm not sure what color-ints even are in the first place. If someone could describe to me what the Color.rgb method actually does to an intensity value, I could then manually code that in C. Cheers.

like image 771
NavMan Avatar asked Dec 31 '25 18:12

NavMan


1 Answers

Take a look:

public static int rgb(int red, int green, int blue) {
  return (0xFF << 24) | (red << 16) | (green << 8) | blue;
}

Source

like image 196
mibollma Avatar answered Jan 02 '26 07:01

mibollma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!