This site requires JavaScript, please enable it in your browser!
Greenfoot back
SPower
SPower wrote ...

2012/11/11

Color to integer

SPower SPower

2012/11/11

#
Hi all, Most of you probably know about the method called 'getRGB' in the Color class. But, is there a way to do that yourself, so you don't have to create a Color instance each time you want an integer for a color? Thanks.
erdelf erdelf

2012/11/11

#
Could you be a bit more specific, I dont really know what you want
SPower SPower

2012/11/11

#
Well, a method on color called getRGB returns an integer which holds the 4 values of the color (red, green, blue and alpha). I wanna know how to create that integer yourself, so you've got an integer which holds 4 color values.
davmac davmac

2012/11/11

#
int rgb = (alpha << 24) + (red << 16) + (green << 8) + blue;
Each of alpha, red, green and blue must be in the range 0 - 255.
SPower SPower

2012/11/11

#
@davmac Thanks so much, that's exactly what I needed!
You need to login to post a reply.