1

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

1 回答 1

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 都不能正常工作。所以我最终

于 2018-08-07T09:35:14.973 回答