我试图改变JavaFX中某些图像的颜色。例如,如果我插入这些RGB值(185,74,72),我会得到不同的结果。我用Paint检查了RGB结果,它是(205,183,183)。你们中的任何人都知道为什么吗?
这是代码:
VBox icon = new VBox();
HBox cell = new HBox(5);
Circle circle = new Circle(12, 12, 18);
ImageView iv = new ImageView(ICON_URL);
ColorAdjust ca = new ColorAdjust();
float[] hsb = new float[3];
Color.RGBtoHSB(185, 74, 72, hsb);
ca.setHue(hsb[0]);
ca.setSaturation(hsb[1]);
ca.setBrightness(hsb[2]);
iv.setClip(circle);
iv.setEffect(ca);
icon.getChildren().addAll(iv);
cell.getChildren().addAll(icon);
答案 0 :(得分:0)
我尝试了下面的代码,但是当我将对比度设置为1.0时却变成了白色而不是蓝色
//Instantiating the ColorAdjust class
ColorAdjust colorAdjust = new ColorAdjust();
// https://stackoverflow.com/questions/37561747/from-rgb-to-hsv-color-rgbtohsb-in-java-returns-a-different-result
//Setting the contrast value
colorAdjust.setContrast(1.0);
//Setting the hue value
colorAdjust.setHue(color.getHue());
//Setting the brightness value
colorAdjust.setBrightness(color.getBrightness());
//Setting the saturation value
colorAdjust.setSaturation(color.getSaturation());
//Applying color adjust effect to the ImageView node
imageView.setEffect(colorAdjust);
然后我尝试了其中的代码,以查看png和svg不能正常工作。所以我结束了