In order to save Color attributes of a graphical object in my application, I saved the string representation of this Color in a data file.
For instance, for red I save: java.awt.Color[r=255,g=0,b=0]
.
How can I convert this string representation into a Color so that I can use it again after loading my data file ?
Thank you.
In . NET you can achieve something like this: Color yellowColor = Color. FromName("yellow");
Paint - Double click on any color at the bottom of the screen. - Choose "Define Custom Colors". - Select a color and/or use the arrows to achieve the desired color. are the numbers needed to create your new Java color.
It's a dark brown. 3 of 3 found this helpful.
You may wish to use getRGB()
instead of toString()
. You can call
String colorS = Integer.toString(myColor.getRGB());
Then you can call
Color c = new Color(Integer.parseInt(colorS));
Stephan's answer helped me with this. However, I found that I needed to add a 'true' to the syntax in order to restore the color.
// convert to string
String colorS = Integer.toString(myColor.getRGB());
// restore colour from string
Color c = new Color(Integer.parseInt(colorS), true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With