iphone - CGColorGetComponents equivalent in Android -


I am porting portals from iPhone to Android related to RGB colors.

Is CGColorGetComponents in Android?

I usually get my arguments using beta-level operations. You can wrap it in a supportive method which gives it as an array if it is more convenient.

  public int [] getColorComponents (int color) {int alpha = (color> & gt; 24) & amp; 0xff; Int red = (color> 16) & amp; 0xff; Int Green = (Color> 8) & amp; 0xff; Int Blue = Color & amp; 0xff; Return the new int [] {alpha, red, green, blue}; }   

If you need a float, you can do something like

  public float [] getColorComponents (int color) {int alpha = ( Color> & gt; 24) & amp; 0xff; Int red = (color> 16) & amp; 0xff; Int Green = (Color> 8) & amp; 0xff; Int Blue = Color & amp; 0xff; Float A = Float Alpha / 255; Float R = (float) red / 255; Float g = (float) green / 255; Float B = (float) blue / 255; New float return [] {a, r, g, b}; }   

If you are doing this many times (such as looping through a pixel in a bitmap), then you probably want to use the same array and pass it one Instead of turning on the new array,

Comments