To get a Color
object in Java from RGB values, you can use the Color
class's Color(int r, int g, int b)
constructor, which takes the red, green, and blue values as arguments and returns a new Color
object.
Here's an example of how to use the Color
constructor to get a Color
object from RGB values:
import java.awt.Color; public class Main { public static void main(String[] args) { Color color = new Color(255, 0, 0); // red System.out.println(color); // prints "java.awt.Color[r=255,g=0,b=0]" } }Source:www.lautturi.com
In this example, a new Color
object is created with red, green, and blue values of 255, 0, and 0, respectively. This creates a red color.
The RGB values should be integers in the range 0 to 255.