gpt4 book ai didi

java - Java中从RGB到HSV(Color.RGBtoHSB)返回不同的结果

转载 作者:太空宇宙 更新时间:2023-11-04 12:33:45 25 4
gpt4 key购买 nike

我正在尝试更改 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);

最佳答案

我尝试了下面的代码,但当我将对比度设置为 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 都无法正常工作。所以我最终

关于java - Java中从RGB到HSV(Color.RGBtoHSB)返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37561747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com