【问题标题】:From RGB to HSV (Color.RGBtoHSB) in Java returns a different resultJava中的从RGB到HSV(Color.RGBtoHSB)返回不同的结果
【发布时间】:2016-06-01 07:10:26
【问题描述】:

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

【问题讨论】:

  • 你得到了什么结果?
  • @MichaelMarkidis 该图像具有不同的颜色(较浅的颜色)。修改后图像的 RGB 为 (205, 183, 183)。
  • 能否请您提供使用上述sn-p的代码?
  • @SubOptimal 我编辑了代码。这不完全一样,但这只是我所做的一个例子

标签: java javafx rgb hsv hsb


【解决方案1】:

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

【讨论】:

  • hmm .. 这不是答案,不是吗?
  • 还没有 - 我必须添加一个链接到我最终得到的结果
猜你喜欢
  • 1970-01-01
  • 2012-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-22
  • 1970-01-01
相关资源
最近更新 更多