I want to get the RGB value of the selected color from ColorPicker in Matlab. For example to display the ColorPicker I use:
pp2 = com.mathworks.mlwidgets.graphics.ColorPicker(0,0,'');
[j1,c1]=javacomponent(pp2,[450,260,30,20],gcf);
After that, how can I get the selected value?
Use j1.Value
. That is a java.awt.Color
, and you can get the RGB
values with j1.Value.getRed()
, j1.Value.getGreen()
, and j1.Value.getBlue()
. These values are in the range [0, 255].
Another way is to use the getRGBComponents()
method:
colour = j1.Value.getRGBComponents([]);
Here, the values are in the range [0, 1] (cf. Converting Java vectors to Matlab arrays)