Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Apr 3, 2000

The Color Constructor

When you construct a Color object in Java, you can supply the arguments in three ways. The most familiar way is to provide three int values each in the range 0-255, with each value corresponding to the Red, Green, or Blue component. For example Color (255,0,0) creates a pure red color.

However, you can also provide three float values, each in the range 0.0 to 1.0, with each value corresponding to the red, green, or blue component. The final method can save space if memory is critical, but it's a little less obvious. You can supply a single int value by multiplying the red value (expressed as 0-255) by 65536, the green value by 256, and then adding those results to the blue value. For example, you could express the color with the values Red=125, Green=45, Blue=77 as the integer 8203597 (8192000+11520+77).
Manoj K.
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date