0

How can I convert a Color value back to RGBA values.

For example I use

Color.rgba8888(r, g, b, a) to create an int value which corresponds to that color, how can I convert it back to the R G B A values?

CodeCamper
  • 6,609
  • 6
  • 44
  • 94

2 Answers2

0

rgba8888 creates an int representation of that color. What you want instead is to use this constructor to make your color...

Color custom = new Color(1,.5f,0,1);

then you can extract the color values later with

custom.a 

r,g, and b
CodeCamper
  • 6,609
  • 6
  • 44
  • 94
0

This code Should work for an rgba8888 format it could work for other color formats here's a link to a similar forearm where i got the code idea from

João Silva

int pixel = rgba8888 format

r = ( ( (all[5] & 0xff000000)>>24 ));
g +=  ( ((all[i] & 0x00ff0000)>>16)*weight[i]);
b +=  ( ((all[i] & 0x0000ff00)>>8)*weight[i]);
a +=  ( ((all[i] & 0x000000ff))*weight[i]);

pixel = ((int) r << 24 | (int)g << 16 | (int)b << 8 | (int)a );
Hunter
  • 1
  • 1