Do you know if it's possible to convert an object :Color
to an array of double
containing its R, its G and its B, in one line ?
It would be very practical for me because I wrote a photo-retouching function which has to be independent of the implementation's constraints (example : the language used). So this function needs a double[]
as parameter and not a :Color
.
For the moment, the function has three double
as parameters but it's less practical.
PS : I don't want to just create myself a double[]
and fill it with getRed
, etc. : I really want to create and fill this array in one instruction.
答案 0 :(得分:0)
PS:我不想创建一个双[]并填写它 getRed等:我真的想在一个中创建并填充这个数组 指令。
因为这是一项非常简单的任务,是什么阻止你编写自己的方法呢?示例实现:
private double[] getColors(Color c) {
return new double[]{c.getRed(), c.getGreen(), c.getBlue()};
}
用法:
Color c = Color.RED;
System.out.println(Arrays.toString(getColors(c)));
结果:
[1.0,0.0,0.0]