如何圆化rgb颜色java

如何圆化rgb颜色java,java,colors,rounding,Java,Colors,Rounding,我有一个问题,从一个图像,我需要得到每个像素的rgb颜色,但我不想要所有的颜色,例如 “如果像素为黄色阴影/色调”,则函数必须返回Color.yellow “如果像素是蓝色的阴影/色调”函数必须返回Color.blue 提前谢谢你的帮助 import javafx.scene.image.Image; import javafx.scene.image.PixelReader; import javafx.scene.paint.Color; public class ColorPicker

我有一个问题,从一个图像,我需要得到每个像素的rgb颜色,但我不想要所有的颜色,例如

“如果像素为黄色阴影/色调”,则函数必须返回Color.yellow

“如果像素是蓝色的阴影/色调”函数必须返回Color.blue

提前谢谢你的帮助

import javafx.scene.image.Image;
import javafx.scene.image.PixelReader;
import javafx.scene.paint.Color;

public class ColorPicker {


private Image img;
private PixelReader pixels;

public ColorPicker(Image image) {
this.img=image;
pixels=img.getPixelReader();
}

public Color getColor(int row,int column) {
Color tmp= pixels.getColor(row, column);

return null;
}

您可以检查像素的RGB代码,并根据最近的端点对值进行四舍五入。例如,如果给定值在0-127舍入到0的范围内。如果该值在128-255区间内,则四舍五入为255。这将适用于主颜色。如果必须支持更多颜色,可以增加粒度。(0-63到0、64-127到127、128-191到128等等)。您可以检查像素的RGB代码,并根据最近的端点对值进行四舍五入。例如,如果给定值在0-127舍入到0的范围内。如果该值在128-255区间内,则四舍五入为255。这将适用于主颜色。如果必须支持更多颜色,可以增加粒度。(0-63到0,64-127到127,128-191到128等等)。